This is the mail archive of the gcc-prs@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]

c++/296: Re: templates and function attributes don't play well together



>Number:         296
>Category:       c++
>Synopsis:       templates and function attributes don't play well together
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    unassigned
>State:          analyzed
>Class:          doc-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jun 09 00:46:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Corey Kosak <kosak@cs.cmu.edu>
>Release:        2.95.2
>Organization:
>Environment:
>Description:
 Date: Thu, 08 Jun 2000 18:03:11 -0400
 Original-Message-ID: <17582.960501791@amphipolis.cmcl.cs.cmu.edu>


 $ cat b5.cc && g++ -v
 #include <iostream.h>

 template<class FP> void apply(FP func)
 {
   func(10);
 }

 void p1(int);
 void p2(int) __attribute__((ATTRIBUTE));

 void p1(int x)
 {
   cout <<"p1's argument is " <<x <<endl;
 }

 void p2(int x)
 {
   cout <<"p2's argument is " <<x <<endl;
 }

 int main()
 {
 #if P1_FIRST
   apply(p1);
   apply(p2);
 #else
   apply(p2);
   apply(p1);
 #endif

   return 0;
 }


 $ g++ '-DATTRIBUTE=regparm(3)' -DP1_FIRST b5.cc && a.out
 p1's argument is 10
 p2's argument is 134521312

 $ g++ '-DATTRIBUTE=regparm(3)'            b5.cc && a.out
 p2's argument is 10
 p1's argument is 134521201


 Notice that the compiler can generate the proper version of apply for either
 p1 or p2 but not both.

 ------------------------------------------------------------------------

 A related problem with a different function attribute:

 $ g++ -DATTRIBUTE=stdcall b5.cc && a.out
 /usr0/kosak/tmp/ccM9vWmC.s: Assembler messages:
 /usr0/kosak/tmp/ccM9vWmC.s:138: Fatal error: Symbol apply__H1ZPFi_v_X01_v already defined.

 ------------------------------------------------------------------------

 I'll leave the analysis to the experts, but in my opinion the fundamental
 source of the problem is that function attributes really want to be part of
 the language's type system, so that they can participate in template matching,
 name mangling, and the like.

 The examples using the first function attribute show that the compiler is
 capable of emitting the right kind of 'apply' in either case (using the proper
 calling convention for its indirect function call) but it evidently is emitting
 only one version of 'apply' when it really needs two.

 The second example shows that the compiler does correctly emit two different
 versions of the 'apply' function but unfortunately assigns them the same
 mangled name so that the subsequent assembly operation fails with a duplicate
 symbol.

 [MvL: IMO, the compiler should reject the code as not supported.]

>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:

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