[cxx-abi-dev] Mangling of function-to-pointer conversion
Jason Merrill
jason at redhat.com
Wed Jan 4 14:58:35 UTC 2012
On 03/04/2011 12:17 PM, Jason Merrill wrote:
> A related case:
>
> template<typename T> int cmp1(T a, T b);
> template<typename T> int cmp2(T a, T b);
> template<typename T, int (*cmp)(T, T)> struct A { };
> template <typename T> void f (A<T,cmp1> &);
> void g()
> {
> A<char,cmp1> a;
> f(a);
> }
>
> How do we mangle 'cmp1' in the signature of f? The ABI doesn't say
> anything specific about how to mangle unresolved overloading.
>
> G++ currently crashes on this testcase, but some obvious fixes lead it
> to generate "4cmp1", i.e. <unresolved-name>, which seems consistent with
> the mangling in a dependent call.
> EDG 4.2 mangles it as adL_Z4cmp1, which doesn't seem to match anything
> in the spec; it seems to be treating the cmp1 template as an extern "C"
> function.
Clang also produces 4cmp1 for this testcase. Curiously, if I adjust the
testcase to
template<typename T> int cmp1(T a, T b);
int cmp2(char a, char b);
template<typename T, int (*cmp)(T, T)> struct A { };
template <typename T> void f (A<T,cmp1> &);
template <typename T> void f (A<T,cmp2> &);
void g()
{
A<char,cmp1> a;
f(a);
A<char,cmp2> a2;
f(a2);
}
For the second F I get three different results from the three compilers:
EDG gives _Z1fIcEvR1AIT_XadL_Z4cmp2ccEEE, which is consistent with its
treatment of the cmp1 case (i.e. adding the unwritten address operation).
G++ with my patch gives _Z1fIcEvR1AIT_L_Z4cmp2ccEE, treating cmp2 as a
simple literal.
Clang gives _Z1fIcEvR1AIT_XL_Z4cmp2ccEEE, wrapping the literal in the
X/E expression delimiters. This seems like a bug.
> I tried to create an analogous dependent call to see what it
> would do in that case:
>
> template <class T, int I> struct B { };
> template <class T> void h(B<T,sizeof(cmp1(T(),T()))>);
>
> void i()
> {
> B<int,sizeof(int)> b;
> h(b);
> }
>
> but EDG 4.2 rejects this testcase.
EDG 4.3 produces _Z1hIiEv1BIT_Xszcl4cmp1cvS1__EcvS1__EEEE for this
testcase, as do GCC and Clang.
Jason
More information about the cxx-abi-dev
mailing list