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]

Re: Bug with egcs-19990428 on i586-pc-linux-gnulibc1 ?



Alexandre Oliva replied with:

>On Apr 29, 1999, Andrew Pollard <andrew@odie.demon.co.uk> wrote:
>
>> struct A {
>>         A(int=0, int=0);
>> };
>> #define B() static A _A(0)
>>
>> #define B() static A _A()

>Despite the apparently similar syntax, these are two completely
>different C++ declarations.
>
>`A _A(0);' declares and defines an object named _A, and directly
>initializes it with 0.
>
>`A _A();', on the other hand, is just the declaration of a function
>`_A', without arguments, returning an A.  There's no initialization to 
>take place here, so the crash does not occur.

True... I realised this when I saw your message... I was too much trying
to cut down on the example (it first appeared in a huge program, and I
was trying to get the example as small as possible...)

What I meant to write was :-) the following

main.cxx:
------------------------------------------------------------------------
#include "A.h"
B();
int main() { return(0); }
------------------------------------------------------------------------
A.h:
------------------------------------------------------------------------
struct A {
        A(int, int);
};
#define B() static A _A(0, 0)
------------------------------------------------------------------------
A.cxx:
------------------------------------------------------------------------
#include "A.h"
B();
A::A(int, int) {}
------------------------------------------------------------------------

Fails, with 'g++ -O main.cxx' A.cxx, but

A.h:
------------------------------------------------------------------------
struct A {
        A(int);
};
#define B() static A _A(0)
------------------------------------------------------------------------
A.cxx:
------------------------------------------------------------------------
#include "A.h"
B();
A::A(int) {}
------------------------------------------------------------------------

works.... (ie, with only one parameter to A() is fine, two aren't)

>But we do indeed have a bug, because the first alternative should work too.

Good, I thought so.

>Suggested (untested) workaround: use unnamed namespaces instead of
>static.
>
>#define B() namespace { A _A(0); }

Nope, 'fraid not. Same crash in __do_global_ctors_aux :-(

Andrew.
--
Andrew Pollard, Auto Simulations Ltd. UK. | home: andrew@odie.demon.co.uk
2 Milbanke Court, Milbanke Way, Bracknell | work: Andrew_Pollard@autosim.com
Tel/Fax: (+44(0)1344) 426486x103 / 426615 | http://www.odie.demon.co.uk


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