public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/9043: incorrect name mangling for array dimension in template function
@ 2002-12-23  9:36 catherin
  0 siblings, 0 replies; only message in thread
From: catherin @ 2002-12-23  9:36 UTC (permalink / raw)
  To: gcc-gnats


>Number:         9043
>Category:       c++
>Synopsis:       incorrect name mangling for array dimension in template function
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Dec 23 09:36:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Catherine Morton
>Release:        gcc 3.2
>Organization:
>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
>Description:
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)

>How-To-Repeat:
g++ -c abc.cpp
nm abc.o
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-12-23 17:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-23  9:36 c++/9043: incorrect name mangling for array dimension in template function catherin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).