c++/1600: The placement of __attribute__ confuses g++

fgouget@codeweavers.com fgouget@codeweavers.com
Sun Apr 1 00:00:00 GMT 2001


>Number:         1600
>Category:       c++
>Synopsis:       The placement of __attribute__ confuses g++
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Tue Jan 09 19:06:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     Francois Gouget
>Release:        CVS 2001/01/08
>Organization:
>Environment:
Debian Linux on Intel ('testing' distribution as of about 2001/01/08)
libc6: 2.2-6
>Description:
   When compiling the code included below with g++ from 
CVS 2001/01/08 I get:

$ /usr/local/opt/gcc-20010108/bin/g++ -c test1.cpp
test1.cpp:14: cannot convert `void (*)()' to `void (*)()' for argument `1' to 
   `int atexit(void (*)())'

   Here's more information about g++ used:

$ /usr/local/opt/gcc-20010108/bin/g++ -v
Reading specs from /usr/local/opt/gcc-20010108/bin/../lib/gcc-lib/i686-pc-linux-gnu/2.97/specs
Configured with: ./src/configure --prefix=/usr/local/opt/gcc --exec-prefix=/usr/local/opt/gcc --enable-shared --enable-threads --enable-languages=c,c++
gcc version 2.97 20010108 (experimental)

   The same code compiles fine if the second declaration of 
m_func is used instead of the first one, or if one uses g++ 
2.95.2. On my machine that would be:

$ g++ -v
Reading specs from /usr/lib/gcc-lib/i386-linux/2.95.2/specs
gcc version 2.95.2 20000220 (Debian GNU/Linux)


   Maybe the placement of __attribute__ is illegal, 
although it does seem allowed in other contexts, but in 
any case g++ should not complain about the call to atexit 
(which is why I have set Class to rejects-legal).

   Before I managed to reproduce this problem in a small 
example I had this problem in a piece of code (in the MFC) 
where m_func and the atexit call were thousands of lines 
apart. I found that fixing all the m_func-style 
definitions as per the workaround was necessary before 
g++ would stop complaining about atexit.
   This problem seems to only affect the declaration of 
pointers to function that are a field of a class. If the 
declaration concerns a global variable or a function 
parameter the placement of __attribute__ seems to cause no 
ill side-effect (i.e. I did not have to change those).

   On last word: the reason I'm using g++ from CVS is 
because I need the '__attribute__((com_interface))'.
>How-To-Repeat:
Compile the following:

--- cut here ---
extern int atexit (void (*__func) (void)) throw ();

class SomeClass
{
public:
    void  (__attribute__((__stdcall__)) *m_func)();
    //void __attribute__((__stdcall__)) (*m_func)();
};

void foo()
{
}

char _term = (char)atexit(&foo);
--- cut here ---
>Fix:
   The workaround is to move __attribute__ out of the 
parenthesis enclosing the name of the pointer to function
(see the commented out declaration of m_func). 
>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the Gcc-prs mailing list