public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "casey dot shaar at pkinetics dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/27941] New: offsetof produces possibly erroneous warnings Date: Wed, 07 Jun 2006 22:43:00 -0000 [thread overview] Message-ID: <bug-27941-12798@http.gcc.gnu.org/bugzilla/> (raw) [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain, Size: 2478 bytes --] When working on an old code base, porting from Windows to Linux, using gcc version 4.1.0 20060304 (Red Hat 4.1.0-3) on my Fedora system, I got a series of warning from a header file which uses offsetof in several places - here's an example: PROM800.h: In member function void ATPromInfo8C::UpdateVersion(): PROM800.h:750: warning: invalid access to non-static data member ATPromInfo8C::CRC of NULL object PROM800.h:750: warning: (perhaps the offsetof macro was used incorrectly) Based on my understanding of offsetof, these warnings seemed unnecessary. After some experimentation, I discovered that this warning is only issued when offsetof is used with classes or structures which have a constructor. If a class or structure omits code for construction, no warning is issued. If code is included in the class or structure for construction, or just the declaration of constructors is included, then the above warning is issued. Below is a screen dump of the source code and the compile output with and without the constructor: /////////////////////////////////////////////////////////////////////////// #[cshaar@localhost PK76OTDR]$ more foo.cpp #include <stdlib.h> #include <stdio.h> #include <stddef.h> class goo { public: #if defined(BREAKIT) goo(int a); #endif int bar; }; struct foo { #if defined(BREAKIT) foo() { } #endif int bar; }; int main(int, char*[]) { size_t s = offsetof(foo,bar); size_t g = offsetof(goo,bar); return 0; } [cshaar@localhost PK76OTDR]$ cc foo.cpp [cshaar@localhost PK76OTDR]$ cc -DBREAKIT foo.cpp foo.cpp: In function int main(int, char**): foo.cpp:26: warning: invalid access to non-static data member foo::bar of NULL object foo.cpp:26: warning: (perhaps the offsetof macro was used incorrectly) foo.cpp:27: warning: invalid access to non-static data member goo::bar of NULL object foo.cpp:27: warning: (perhaps the offsetof macro was used incorrectly) [cshaar@localhost PK76OTDR]$ /////////////////////////////////////////////////////////////////////////////// Thanks, Casey Shaar -- Summary: offsetof produces possibly erroneous warnings Product: gcc Version: 4.1.0 Status: UNCONFIRMED Severity: minor Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: casey dot shaar at pkinetics dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27941
next reply other threads:[~2006-06-07 22:39 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2006-06-07 22:43 casey dot shaar at pkinetics dot com [this message] 2006-06-07 22:44 ` [Bug c++/27941] " pinskia at gcc dot gnu dot org 2008-06-08 1:41 ` tristan_schmelcher at alumni dot uwaterloo dot ca
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-27941-12798@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).