This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/6262: Incorrect error message reported when applying sizeof() to non-static class member
- From: neil at neilpearce dot com
- To: gcc-gnats at gcc dot gnu dot org
- Date: 11 Apr 2002 18:48:26 -0000
- Subject: c++/6262: Incorrect error message reported when applying sizeof() to non-static class member
- Reply-to: neil at neilpearce dot com
>Number: 6262
>Category: c++
>Synopsis: Incorrect error message reported when applying sizeof() to non-static class member
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Apr 11 11:56:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: neil@neilpearce.com
>Release: unknown-1.0
>Organization:
>Environment:
SunOS 5.8 Generic_108528-01 sun4u sparc SUNW,Ultra-5_10
Reading specs from /usr/local/gcc3.0.4/lib/gcc-lib/sparc-sun-solaris2.8/3.0.4/specs
Configured with: ../gcc-3.0.4/configure --exec-prefix=/usr/local/gcc3.0.4
Thread model: posix
gcc version 3.0.4
>Description:
When using sizeof() on a non-static class member,
the error message reported differs depending
on the context in which the code appears.
GCC 3.0.4 gives an incorrect error message when
this is attempted within a constructor
>How-To-Repeat:
Individually attempt to compile the two sources
below, and examine the error messages returned by
GCC 3.0.4
----------
#include <iostream>
struct X {
char x[1];
};
struct Y {
Y() { std::cout << sizeof(X::x); }
}
Under GCC 3.0.4, compiliation of the above results in
z.cc: In constructor `Y::Y()':
z.cc:8: cannot convert a pointer of type `Y' to a pointer of type `X'
----------
#include <iostream>
struct X {
char x[1];
};
int main() {
std::cout << sizeof(X::x);
}
Under GCC 3.0.4, compilation of the above results in
z.cc:4: member `X::x' is non-static but referenced as a static member
z.cc:8: at this point in file
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: