g++-3.3 should warn about an object declared as a class that is later on used as a "struct". This would simplify the generation of portable code as at least one other popular compiler will generate warnings for this case that could be easily avoided by this additional g++ warning. This would make life simpler for those that have to support several platforms. This issue is not whether the requested warning is "useful" as a C++ warning. Besides, implementation seems to be simple for me. Save the following code as "foo.cpp" /* snip */ class A { int x; }; int main(int,char) { struct A a; return 0; } /* snip */ And compile with $ g++-3.3 -Wall -pedantic foo.cpp The resulting code works. (-; It would be nice if g++ could generate a warning (e.g. by passing a -Wstruct-class-equivalence) that "class A" has been used as "struct A a;" in main(), instead of "class A a;" or rather "A a;".
I tried to locate the spot in the standard that says whether struxt X x; is really legal only if X is declared as a "struct", rather than declared as a "class". I was under the impression that it wouldn't matter, and couldn't find wording. If it really doesn't matter, then I think it's not gcc's job to warn about stuff simply because other compilers are not standards conforming. It's their task to fix it. It the standard prescribes that "struct X x" is only allowed if X is really a struct, then we have a bug in gcc (and in icc, FWIW). Nathan, your opinion? W.
Subject: Re: g++-3.3 should warn about class/struct equivalence "pinskia@physics.uc.edu" <gcc-bugzilla@gcc.gnu.org> writes: | PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org. | | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=10930 | | | pinskia@physics.uc.edu changed: | | What |Removed |Added | ---------------------------------------------------------------------------- | Summary|[diagnosis] g++-3.3 should |g++-3.3 should warn about | |warn about class/struct |class/struct equivalence | |equivalence | | I don't see why GCC should warn about that equivalence. As far as I'm concerned this PR should be closed. -- Gaby
Metrowork's CodeWarrior has this warning, if everyoone agrees that we do not need this warning I will close this bug but right now I leaving it open.
Subject: Re: g++-3.3 should warn about class/struct equivalence "pinskia@physics.uc.edu" <gcc-bugzilla@gcc.gnu.org> writes: | PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org. | Metrowork's CodeWarrior has this warning, if everyoone agrees that | we do not need this warning I will close this bug but right now I | leaving it open. The point is what to warn about? There is no point in warning about class plus; struct plus { /* ... */ }; -- Gaby
Closing as there is no reason to warn about this except to be emulating other compilers which we do not want to do.
I finally found (by accident) that part of the standard that explicitly allows gcc's behavior in this case, so closing the PR is justified. The clause in question is 7.1.5.3/3, which states that [...] the enum keyword shall be used to refer to an enumeration, the union class-key shall be used to refer to a union, and either the class or struct class-key shall be used to refer to a class declated using the class or struct class-key. This should settle the matter. W.