c++/4477: sizeof on nested class members doesn't compile

roman.kagan@itep.ru roman.kagan@itep.ru
Fri Oct 5 03:56:00 GMT 2001


>Number:         4477
>Category:       c++
>Synopsis:       sizeof on nested class members doesn't compile
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Fri Oct 05 03:56:03 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     
>Release:        3.0.1
>Organization:
>Environment:
System: Linux jaguar 2.4.10 #1 Mon Sep 24 16:48:49 MSD 2001 i686 unknown
Architecture: i686

	
host: i386-redhat-linux-gnu
build: i386-redhat-linux-gnu
target: i386-redhat-linux-gnu
configured with: ../gcc-3.0.1/configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-languages=c++,f77,java --enable-threads=posix --with-system-zlib i386-redhat-linux

Also reproduced with gcc-3.0.1 on sparc-sun-solaris2.7
>Description:
sizeof applied to a member of a nested class doesn't compile.
The diagnostics is different depending on whether sizeof appears in a
member function of the enclosing class or in a global function, but
seems to be invalid in either case.
>How-To-Repeat:
class foo {
public:
  class bar {
  public:
    int z;
  };
  void y();
};

void foo::y()
{
  int i = sizeof(foo::bar::z);
}
void y()
{
  int i = sizeof(foo::bar::z);
}

>Fix:
	
>Release-Note:
>Audit-Trail:
>Unformatted:
 >>> g++ -c foo.cc 
 foo.cc: In member function `void foo::y()':
 foo.cc:12: cannot convert a pointer of type `foo' to a pointer of type 
    `foo::bar'
 foo.cc: In function `void y()':
 foo.cc:5: member `foo::bar::z' is non-static but referenced as a static member
 foo.cc:16: at this point in file
 



More information about the Gcc-bugs mailing list