This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: c++/8963: [3.2/3.3 regression] [ABI] The same template instance ismangled with 2 different names


I've asked our C++ ANSI standards rep to look at this problem and he does
not believe that the testcase is invalid... see comments below

The expression in the testcase does not involve template parameters, so it
is not ill-formed according to paragraph 7,8  section 14.5.5.1

-----
Catherine Morton
VAC++ Kernel Development
catherin@ca.ibm.com
(905) 413-4328

----- Forwarded by Catherine Morton/Toronto/IBM on 12/30/2002 02:46 PM
-----
                                                                                                                                
                      Sandor Mathe                                                                                              
                                               To:      Catherine Morton/Toronto/IBM@IBMCA                                      
                      12/30/2002 12:20         cc:                                                                              
                      PM                       From:    Sandor Mathe/Toronto/IBM@IBMCA                                          
                                               Subject: Re: c++/8963: [3.2/3.3 regression] [ABI] The same template instance is  
                                               mangled with 2 different names(Document link: Catherine Morton)                  
                                                                                                                                
                                                                                                                                
                                                                                                                                
                                                                                                                                
                                                                                                                                
                                                                                                                                



Catherine,

Hmm, I should have remembered that section.  But I think they are wrong.

In:
template <int J, int K> void stuff( thing<(signed char)(thirty)> x) {}

There is no expression involving template parameters.  "thing" is a
complete instantiation.  Paragraph 7 and 8 below do not apply.

They would if the test case was like:

template <int> struct thing {thing(int){} };

template <int I> void f ( thing<I>);
template <int I> void f ( thing<(unsigned char)(I)>);


Also this test case compiles clean on gcc and should not (violates the
ODR):
template <int I > class A{};

const int one=1;
const int uno=1;

template <class T> void f(A<one>) {}
template <class T> void f(A<(char)(uno)>) {}  // error redefiniton of f

If you remove the cast gcc gives the error message as well.


Sandor  Mathe

VisualAge C++ Development
IBM Canada Ltd., C2/KD2/8200/MKM
8200 Warden Avenue
Markham, Ontario  L6G 1C7
-- Phone 905-413-2594  -- Tie 969-2594 -- Fax 905-413-4839



                                                                                                                                
                      Catherine Morton                                                                                          
                                               To:       Sandor Mathe/Toronto/IBM@IBMCA, Howard Nasgaard/Toronto/IBM, Michael   
                      12/30/2002 11:02          Wong/Toronto/IBM@IBMCA                                                          
                      AM                       cc:       Derek Truong/Toronto/IBM@IBMCA                                         
                                               From:     Catherine Morton/Toronto/IBM@IBMCA                                     
                                               Subject:  Re: c++/8963: [3.2/3.3 regression] [ABI] The same template instance is 
                                                mangled with 2 different names                                                  
                                                                                                                                
                                                                                                                                
                                                                                                                                



This is the defect I reported against gcc indicating that the same template
is mangled with 2 different names... this is the cast-problem explained in
defect 232734/272733

gcc has basically closed the defect claiming that they don't have to be
able to determine that both are the same template
Here's the referenced section of the document

7 Two function templates are equivalent if they are declared in the same
  scope, have the same name, have identical  template  parameter  lists,
  and  have  return  types and parameter lists that are equivalent using
  the rules described above to compare  expressions  involving  non-type
  template  parameters.  Two function templates are functionally equiva-
  lent if they are equivalent except that one or more  non-type  expres-
  sions that involve template parameters in the return types and parame-
  ter lists are functionally equivalent using the rules described  above
  to  compare  expressions involving non-type template parameters.  If a
  program contains declarations of function templates that are function-
  ally  equivalent  but  not  equivalent,  the program is ill-formed; no
  diagnostic is required.

8 [Note: This rule  guarantees  that  equivalent  declarations  will  be
  linked  with  one  another, while not requiring implementations to use
  heroic efforts to guarantee that functionally equivalent  declarations
  will  be  treated as distinct.  For example, the last two declarations
  are functionally equivalent and would  cause  a  program  to  be  ill-
  formed:
  // Guaranteed to be the same
  template <int I> void f(A<I>, A<I+10>);
  template <int I> void f(A<I>, A<I+10>);

  // Guaranteed to be different
  template <int I> void f(A<I>, A<I+10>);
  template <int I> void f(A<I>, A<I+11>);

  // Ill-formed, no diagnostic required
  template <int I> void f(A<I>, A<I+10>);
  template <int I> void f(A<I>, A<I+1+2+3+4>);
   --end note]

My example is similar to the last example:

The big difference here is that this example does NOT have an expression
involving template parameters

// ---------------- a.cpp ---------------------
#include "def.h"

const int thirty = 30;
template <int J, int K> void stuff( thing<(signed char)(thirty)> x) {}

void great()
{
stuff<7,8>(9);
}
// --------------------------------------------

// ---------------- b.cpp ---------------------
#include "def.h"

const int thirtx = 30;
template <int J, int K> void stuff( thing<(unsigned char)(thirtx)> x);

int main()
{
  stuff<7,8>(9);
}
// --------------------------------------------

// ------------- def.h ------------------------

template <int> struct thing {thing(int){} };

// --------------------------------------------

Our compiler has figured out that there is one instantiation stuff<(int)30>
and we mangle it that way...  however gcc has not figured out that there is
only one, so its mangling the cast expression and the name of the const int
rather than the value.

our name: _Z5stuffILi7ELi8EEv5thingILi30EE   (same name from a.o and b.o)

gcc names(2):
a.o  _Z5stuffILi7ELi8EEv5thingIXcvaL_Z6thirtyEEE
b.o  _Z5stuffILi7ELi8EEv5thingIXcvhL_Z6thirtxEEE

g++ fails to link due to the different names

I don't see any easy way to match what gcc is doing in this case

C.
-----
Catherine Morton
VAC++ Kernel Development
catherin@ca.ibm.com
(905) 413-4328

----- Forwarded by Catherine Morton/Toronto/IBM on 12/30/2002 10:40 AM
-----
                                                                                                                                
                      lerdsuwa@gcc.gnu.                                                                                         
                      org                      To:       Catherine Morton/Toronto/IBM@IBMCA, gcc-bugs@gcc.gnu.org,              
                                                gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org                                         
                      12/25/2002 04:12         cc:                                                                              
                      AM                       Subject:  Re: c++/8963: [3.2/3.3 regression] [ABI] The same template instance is 
                      Please respond to         mangled with 2 different names                                                  
                      lerdsuwa; Please                                                                                          
                      respond to                                                                                                
                      Catherine Morton;                                                                                         
                      Please respond to                                                                                         
                      gcc-bugs; Please                                                                                          
                      respond to                                                                                                
                      gcc-prs; Please                                                                                           
                      respond to                                                                                                
                      nobody; Please                                                                                            
                      respond to                                                                                                
                      gcc-gnats                                                                                                 
                                                                                                                                
                                                                                                                                



Synopsis: [3.2/3.3 regression] [ABI] The same template instance is mangled
with 2 different names

State-Changed-From-To: analyzed->closed
State-Changed-By: lerdsuwa
State-Changed-When: Wed Dec 25 01:12:39 2002
State-Changed-Why:
    The code is ill-formed according to 14.5.5.1 p7,8.  A compiler is not
required to be able to figure out that
    thing<(signed char)(thirty)> is equivalent to
    thing<(unsigned char)(thirty)>

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8963









Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]