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]

(C++) parser bug in handling fn attributes


[ Reposted. First post on Mon, 26 Jul 1999 20:44:16 CDT. ]

The following code shows a bug in the C++ parser when dealing with
function attributes. The C parser does the right thing. I'm using
__stdcall__ on x86/win32 since it's easy to see. On Linux, the same
problem occurs, but more silently due to non-decoration of stdcall
functions.

  extern void *foo (int);
  extern void * __attribute__((__stdcall__)) bar (int);
  extern void *foo (int);

  int main ()
  {
    foo (0);
  }

In this testcase, *only* bar has the stdcall attribute attached, and it
should be only one affected. However, note the symbols below, especially 
the line marked WRONG:

$ i586-cygwin32-gcc -c c++-attrib-fn-bug.cc
$ i586-cygwin32-nm c++-attrib-fn-bug.o
  00000000 b .bss
  00000000 d .data
  00000000 t .text
  00000000 t ___gnu_compiled_cplusplus
	   U ___main
	   U _foo__Fi@4		<<<<< WRONG, should be _foo__Fi.
  00000000 T _main
  00000000 t gcc2_compiled.

If I change the prototype of bar() to not match the prototype of foo(),
the problem goes away[1]; if I change the position of the attribute to
come *before* the return type, the problem goes away[2,3].

[1] This is OK.

  extern void *foo (int);
  extern void * __attribute__((__stdcall__)) bar (char);
  extern void *foo (int);

[2] And so is this.

  extern void *foo (int);
  extern __attribute__((__stdcall__)) void *bar (char);
  extern void *foo (int);

[3] And so is this.

  extern void *foo (int);
  extern void __attribute__((__stdcall__)) *bar (char);
  extern void *foo (int);

This exists in both release and mainline, and causing let's just say
interesting link time errors, and in some cases, bad template code.

Regards,
Mumit


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