The C++ ABI for name mangling has 2 production rules for mangling array dimensions: quoting from the ABI: Array types encode the dimension (number of elements) and the element type. Note that "array" parameters to functions are encoded as pointer types. For variable length arrays (C99 VLAs), the dimension (but not the '_' separator) is omitted. <array-type> ::= A <positive dimension number> _ <element type> ::= A [<dimension expression>] _ <element type> When the dimension is an expression involving template parameters, the second production is used. Thus, the declarations: template<int I> void foo (int (&)[I + 1]) { } template void foo<2> (int (&)[3]); produce the mangled name "_Z3fooILi2EEvRAplT_Li1E_i". gcc mangles the name in the example the same way... however for this testcase: // ------------- abc.cpp ------------ template <int I> void f36(int (*)[2]) {} static const int I=1; template void f36<I>(int (*)[2]); void (*g36)(int (*)[2]) = &f36<I>; // --------------------------------- gcc mangles the name as follows _Z3f36ILi1EEvPALi2E_i The array dimension '2' has been mangled as a literal expression 'Li2E' So gcc has taken the 2nd production for the array dimension If I'm interpreting the standard correctly, this is not correct. The array dimension should only be encoded as an expression if it references the template arguments The correct mangled name should be: _Z3f36ILi1EEvPA2_i (taking the first production instead of the 2nd one) Release: gcc 3.2 Environment: Reading specs from /usr/lib/gcc-lib/powerpc-suse-linux/3.2/specs Configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib --enable-languages=c,c++,f77,objc,java,ada --enable-libgcj --with-gxx-include-dir=/usr/include/g++ --with-slibdir=/lib --with-system-zlib --enable-shared --enable-__cxa_atexit powerpc-suse-linux Thread model: posix gcc version 3.2 How-To-Repeat: g++ -c abc.cpp nm abc.o
Is this true with 3.3 and -fabi-version=0?
I can confirm this on the mainline (20030803) even with -fab-version=0. _Z3f36ILi1EEvPALi2E_i void f36<(int)1>(int (*) [(int)2]) _Z3f36ILi1EEvPA2_i void f36<(int)1>(int (*) [2])
2003-12-16 Nathan Sidwell <nathan@codesourcery.com> PR c++/9043 C++ ABI change: Mangling array indices in templates. * decl.c (compute_array_index_type): Reorganize for earlier template errors. Use value_dependent_expression_p for abi-2. * mangle.c (write_array_type): Check broken mangling for expression indices on abi-1
Subject: Bug 9043 CVSROOT: /cvs/gcc Module name: gcc Changes by: nathan@gcc.gnu.org 2003-12-16 19:50:55 Modified files: gcc/cp : ChangeLog decl.c mangle.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/abi: mangle20-1.C mangle20-2.C Log message: cp: PR c++/9043 C++ ABI change: Mangling array indices in templates. * decl.c (compute_array_index_type): Reorganize for earlier template errors. Use value_dependent_expression_p for abi-2. * mangle.c (write_array_type): Check broken mangling for expression indices on abi-1 testsuite: PR c++/9043 * g++.dg/abi/mangle20-1.C: New test. * g++.dg/abi/mangle20-2.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3813&r2=1.3814 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1161&r2=1.1162 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/mangle.c.diff?cvsroot=gcc&r1=1.93&r2=1.94 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3270&r2=1.3271 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/abi/mangle20-1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/abi/mangle20-2.C.diff?cvsroot=gcc&r1=NONE&r2=1.1