Mangling of function-to-pointer conversion

Mike Herrick mjh at edg.com
Wed Jun 9 16:55:37 UTC 2010


While working on SFINAE mangling, I ran across this issue with an implicit function-to-pointer conversion.  Given:

$ cat test.cpp
template <class T> struct A {
  template <void (*PF)()> struct B {};
};
template <void (*PF)()> struct B {};
void ff();
template <class T> B<&ff> f1(T);
template <class T> B<ff>  f2(T);
template <class T> typename A<T>::template B<&ff> f3(T);
template <class T> typename A<T>::template B<ff>  f4(T);
int main() {
  f1(1);
  f2(1);
  f3(1);
  f4(1);
}
$ g++450 -fabi-version=0 -c test.cpp && nm -u test.o
               U _Z2f1IiE1BIXadL_Z2ffvEEET_
               U _Z2f2IiE1BIXadL_Z2ffvEEET_
               U _Z2f3IiEN1AIT_E1BIXadL_Z2ffvEEEES1_
               U _Z2f4IiEN1AIT_E1BIL_Z2ffvEEES1_
$ eccp -c test.cpp && nm -u test.o
               U _Z2f1IiE1BIXadL_Z2ffvEEET_
               U _Z2f2IiE1BIXadL_Z2ffvEEET_
               U _Z2f3IiEN1AIT_E1BIXadL_Z2ffvEEEES1_
               U _Z2f4IiEN1AIT_E1BIXadL_Z2ffvEEEES1_
$ clang++ -c test.cpp && nm -u test.o
__Z2f1IiE1BILZ2ffvEET_
__Z2f2IiE1BILZ2ffvEET_
__Z2f3IiEN1AIT_E1BIXadL_Z2ffvEEEES1_
__Z2f4IiEN1AIT_E1BIXL_Z2ffvEEEES1_

When ff is used as a nontype template parameter in f2, both g++ and EDG add an "ad" to represent the implied function-to-pointer conversion.  However, that's not the case in f4 where g++ doesn't add the "ad".

The ABI spec says (5.1.5): "Except for the parentheses, therefore, it [the mangled expression encoding] represents the source token stream".  That would seem to indicate that the mangling for f2 is wrong (as is EDG's mangling for f4).

Does anyone know the logic behind adding the "ad" in the mangled name for f2 (and whether or not that same logic applies to f4)?

Curiously, g++ doesn't add the "ad" in dependent cases:

template <class T> auto f5(T p1) -> decltype(p1(f));

Thanks,

Mike Herrick
Edison Design Group


More information about the cxx-abi-dev mailing list