[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

g++-3.3 should warn about class/struct equivalence




 >Submitter-Id:  net
 >Originator:    Thomas Richter
 >Organization:
 >Confidential:  no
 >Synopsis:      g++-3.3 should warn about class/struct equivalence
 >Severity:      non-critical
 >Priority:      medium
 >Category:      c++
 >Class:         change-request
 >Release:       3.3 20030509 (Debian prerelease)
 >Environment:
System: Linux skywise 2.4.20 #7 Thu May 15 19:53:29 CEST 2003 i686 unknown
Architecture: i686

	<machine, os, target, libraries (multiple lines)>
host: i386-pc-linux-gnu
build: i386-pc-linux-gnu
target: i386-pc-linux-gnu
configured with: ../src/configure -v
--enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared
--with-system-zlib --enable-nls --without-included-gettext
--enable-__cxa_atexit --enable-clocale=gnu --enable-debug
--enable-java-gc=boehm --enable-java-awt=xlib --enable-objc-gc i386-linux
 >Description:
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. Besides, implementation seems to be simple for me.
 >How-To-Repeat:
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 that "class A" has been used as "struct A a;" in main(), instead of "class A a;" or rather "A a;".

>Fix:




Reply to: