Mangling ambiguity

Daveed Vandevoorde daveed at edg.com
Fri Apr 28 23:30:25 UTC 2000


I think there is some confusion about the meaning of the "T<num>_"
segments, and it is somewhat related to a problem in the current
standard where the term "template" is not always used consistently.

A template is one of the following things:
	a) a class template
	b) a function template
	c) a member function template
In particular, a regular member (function, static data, class, ...)
of a class template is not a template of its own.  (The standard used 
to say the opposite at one point, but I believe that is now corrected.)

The "T<num>_" segments should only be used to denote types of
instantiations of true templates; not in the instantiation of
template entities.  As it happens, the cannot appear in the
instantiation of class templates since they have no additional
signature.  So really, "T<num>_" should only appear in parameter
and return types of function and member function templates.

Reconsider Matt's original example:

>        template <class T> struct A { };
>        template <class T> struct B { };
> 
>        template <class T> struct X        { void f(T); };
>        template <class T> struct X<A<T> > { void f(T); };
> 

The mangling of:

>     void X<A<int> >::f(int);

is "_ZNXIAIiEE1fEvi"; and that of

>     void X<B<int> >::f(B<int> >);

is "ZNXIBIiEE1fEvS<num>_" for some suitable <num> that I'm too lazy
to determine.

The "T<num>_" segments are necessary in function templates though:

	template<typename T> void f(typename A<T>::X) {}
	template<typename T> void f(typename B<T>::X) {}

Both A<int>::X and B<int>::X may end up resolving to, say, "int"; so we
cannot just resolve the specialization type.  Instead we get:
	_Z1fIiEvN1AIT1_E1XE  and  _Z1fIiEvN1BIT1_E1XE
which could be demangled as:
	void f<int>(A<int>::X)  and  void f<int>(B<int>::X)

Another subtle case is:

	template<typename T1, typename T2> void f(T1, T2);
	template<typename T1, typename T2> void f(T2, T1);

(in different translation units).  Specializations of these are distinct
and must therefore mangle differently.

Either way, the "T<num>_" segments will only appear in the parameter and
return types of function and member function template specializations.
I believe that removes the need the rule for multilevel (nested?)
templates: each template level can safely number its parameters starting
from "1" (or "0" if we prefer to use some smarts as with the "S<num>_"
segments).

Does that make any sense at all?

	Daveed




More information about the cxx-abi-dev mailing list