Bug 10930 - g++-3.3 should warn about class/struct equivalence
Summary: g++-3.3 should warn about class/struct equivalence
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.3
: P2 enhancement
Target Milestone: 3.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-05-22 11:23 UTC by thor
Modified: 2003-06-27 14:42 UTC (History)
3 users (show)

See Also:
Host: i386-pc-linux-gnu
Target: i386-pc-linux-gnu
Build: i386-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2003-05-31 14:01:45


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description thor 2003-05-22 11:23:44 UTC
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;".
Comment 1 Wolfgang Bangerth 2003-05-23 19:01:59 UTC
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.
Comment 2 Gabriel Dos Reis 2003-05-31 12:57:28 UTC
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
Comment 3 Andrew Pinski 2003-05-31 14:01:45 UTC
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.
Comment 4 Gabriel Dos Reis 2003-05-31 14:18:04 UTC
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
Comment 5 Andrew Pinski 2003-05-31 14:46:54 UTC
Closing as there is no reason to warn about this except to be emulating other compilers 
which we do not want to do.
Comment 6 Wolfgang Bangerth 2003-06-27 14:42:24 UTC
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.