This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/25927] New: Spurious offsetof warnings with private members
- From: "rcbilson at plg dot uwaterloo dot ca" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 23 Jan 2006 16:51:51 -0000
- Subject: [Bug c++/25927] New: Spurious offsetof warnings with private members
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Consider:
#include <iostream>
#include <cstddef>
class xxx {
friend int main();
void *q;
public:
void *r;
};
int main() {
std::cout << "offset of xxx::q is " << offsetof( xxx, q ) << "\n";
std::cout << "offset of xxx::r is " << offsetof( xxx, r ) << "\n";
return 0;
}
The class xxx is POD, and the two applications of offsetof should be ok (per
18.1p5). However, g++ warns:
offsetof.cc: In function 'int main()':
offsetof.cc:12: warning: invalid access to non-static data member 'xxx::q' of
NULL object
offsetof.cc:12: warning: (perhaps the 'offsetof' macro was used incorrectly)
offsetof.cc:13: warning: invalid access to non-static data member 'xxx::r' of
NULL object
offsetof.cc:13: warning: (perhaps the 'offsetof' macro was used incorrectly)
Stranger still, if *both* q and r are made public g++ accepts the code without
complaint.
--
Summary: Spurious offsetof warnings with private members
Product: gcc
Version: 4.0.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: rcbilson at plg dot uwaterloo dot ca
GCC build triplet: sparc-sun-solaris2.8
GCC host triplet: sparc-sun-solaris2.8
GCC target triplet: sparc-sun-solaris2.8
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25927