Fwd: Mangling ambiguity with argument packs in template argument lists

Mark Mitchell mark at codesourcery.com
Tue Mar 1 23:39:27 UTC 2011


On 2/28/2011 8:04 AM, Mike Herrick wrote:

> Actually, the patch associated with this message is the patch that should be applied (it includes fixes for both variadic template issues I brought up).

Mike, I've applied the patch.  Thank you!

> Thanks,
> 
> Mike.
> 
> Begin forwarded message:
> 
>> From: Mike Herrick <mjh at edg.com>
>> Date: December 20, 2010 12:41:17 PM EST
>> To: cxx-abi-dev at codesourcery.com
>> Subject: Mangling ambiguity with argument packs in template argument lists
>>
>> We ran into a mangling ambiguity with argument packs in template argument lists (where both use the letter "I"):
>>
>>  <template-args> ::= I <template-arg>+ E
>>  <template-arg> ::= <type>                         # type or template
>>                 ::= X <expression> E               # expression
>>                 ::= <expr-primary>                 # simple expressions
>>                 ::= I <template-arg>* E            # argument pack
>>                 ::= sp <expression>                # pack expansion (C++0x)
>>
>> Here's an example where two different source constructs generate the same mangled name (_Z1fI1BI1AIiEEEDTcmfp_fp_ET_):
>>
>> $ cat foo.cpp
>>  template <class T> auto f(T p1) -> decltype(p1, p1);
>>  template <class T> struct A {};
>> #if FOO
>>  template <class T> struct B {};
>>  B<A<int>> b;
>> #else
>>  template <template <class TT> class T, class ... U> struct B {};
>>  B<A,int> b;
>> #endif
>>  int main() {
>>    f(b);
>>  }
>> $ g++451 -DFOO -std=c++0x foo.cpp
>> /tmp/ccOqFYBI.o(.text+0xc): In function `main':
>> : undefined reference to `decltype ({parm#1},{parm#1}) f<B<A<int> > >(B<A<int> >)'
>> collect2: ld returned 1 exit status
>> $ g++451 -UFOO -std=c++0x foo.cpp
>> /tmp/cc448n5U.o(.text+0xc): In function `main':
>> : undefined reference to `decltype ({parm#1},{parm#1}) f<B<A<int> > >(B<A<int> >)'
>> collect2: ld returned 1 exit status
>> $ 
>>
>> When the demangler gets to the "I" after "1A", it's ambiguous whether the "I" represents an argument pack or a template argument (as noted by g++ 4.5.1 issuing the same demangled name for both cases).
>>
>> To address this, we propose changing the mangling for argument packs to use "J" rather than "I":
>>
>>  <template-arg> ::= J <template-arg>* E              # argument pack
>>
>> This change is not backward compatible.
>>
>> I'm attaching a patch that includes this change with the others that I've proposed.
>>
>> Thanks,
>>
>> Mike.



-- 
Mark Mitchell
CodeSourcery
mark at codesourcery.com
(650) 331-3385 x713



More information about the cxx-abi-dev mailing list