From mboxrd@z Thu Jan 1 00:00:00 1970 From: Daniel Berlin To: Eli Zaretskii Cc: jimb@zwingli.cygnus.com, msnyder@redhat.com, gdb-patches@sources.redhat.com, ac131313@cygnus.com Subject: Re: [RFA] enum enable Date: Wed, 18 Jul 2001 00:34:00 -0000 Message-id: <871yne8zcu.fsf@cgsoftware.com> References: <200107180700.KAA12466@is.elta.co.il> X-SW-Source: 2001-07/msg00446.html Eli Zaretskii writes: >> From: Jim Blandy >> Date: 17 Jul 2001 12:46:32 -0500 >> >> Eli Zaretskii writes: >> > In addition to Andrew's request to change that, GCC 2.7.2.1 barfs if >> > it sees the declaration of a member `enable' together with a prototype >> > of a function `enable' in the same compilation unit. In my case, the >> > function is declared in one of the system headers, so I guess GCC sees >> > it first and protests when the same identifier appears in a struct. >> >> You've *got* to be kidding. >> >> So, the following program gets an error? >> >> extern int foo (void); >> >> struct bar >> { >> int foo; >> }; >> > > No, that one passes. But this one does not: > > enum foobar > { > foo, > bar > }; > > int foo(void); > > $ gcc2721 -c enum.c > enum.c:8: two or more data types in declaration of `foo' > enum.c:8: `foo' redeclared as different kind of symbol > enum.c:4: previous declaration of `foo' > > If I switch the order of the function and enum declaration, the > resulting message might give a clue about what's going on: > > int foo(void); > > enum foobar > { > foo, > bar > }; > > $ gcc2721 -c enum.c > enum.c:6: `foo' redeclared as different kind of symbol > enum.c:2: previous declaration of `foo' > enum.c:6: warning: `foo' was declared `extern' and later `static' > > Actually, now I see that even GCC 2.95.3 reports the same errors. > > [Dig, dig] and it looks like this is expected: my references indicate > that enumeration constants and function names belong to the same > namespace in C programs. Yeah, but in case you still thought gcc was off the hook for this type of failure, check this out: #include struct fill {}; // comment out this line to compile successfully struct y {}; void f() { std::vector x(10); x.insert(x.begin(), 10, y()); } Works fine with 2.95. Perfectly valid C++. Fails miserably with 3.0. Whoops. :) --Dan -- "Women... Can't live with 'em... Can't shoot 'em. "-Steven Wright