public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "jrh5y6virbl36ay at optonline dot net" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/16618] New: In C++, offsetof fails with constant member Date: Sun, 18 Jul 2004 17:36:00 -0000 [thread overview] Message-ID: <20040718173631.16618.jrh5y6virbl36ay@optonline.net> (raw) gcc-3.4.1, Linux kernel 2.4.26, glibc-2.3.2. Configured with: ../gcc-3.4.1/configure --prefix=/opt/gcc-3.4.1 --enable-threads --with-system-zlib --enable-__cxa_atexit --with-cpu=pentium4 --with-arch=pentium4 --with-tune=pentium4 This code: #include <cstddef> struct test { const char a; }; int main(int argc, char *argv[]) { size_t n=offsetof(test,a); } Leads to: $ c++ -c 040718a.cc 040718a.cc: In function `int main(int, char**)': 040718a.cc:10: error: reinterpret_cast from type `const char*' to type `char*' casts away constness The preprocessor output: # 1 "040718a.cc" # 1 "<built-in>" # 1 "<command line>" # 1 "040718a.cc" # 1 "/opt/gcc-3.4.1/lib/gcc/i686-pc-linux-gnu/3.4.1/../../../../include/c++/3.4.1/cstddef" 1 3 # 46 "/opt/gcc-3.4.1/lib/gcc/i686-pc-linux-gnu/3.4.1/../../../../include/c++/3.4.1/cstddef" 3 # 47 "/opt/gcc-3.4.1/lib/gcc/i686-pc-linux-gnu/3.4.1/../../../../include/c++/3.4.1/cstddef" 3 # 1 "/opt/gcc-3.4.1/lib/gcc/i686-pc-linux-gnu/3.4.1/include/stddef.h" 1 3 4 # 151 "/opt/gcc-3.4.1/lib/gcc/i686-pc-linux-gnu/3.4.1/include/stddef.h" 3 4 typedef int ptrdiff_t; # 213 "/opt/gcc-3.4.1/lib/gcc/i686-pc-linux-gnu/3.4.1/include/stddef.h" 3 4 typedef unsigned int size_t; # 49 "/opt/gcc-3.4.1/lib/gcc/i686-pc-linux-gnu/3.4.1/../../../../include/c++/3.4.1/cstddef" 2 3 namespace std { using ::ptrdiff_t; using ::size_t; } # 2 "040718a.cc" 2 struct test { const char a; }; int main(int argc, char *argv[]) { size_t n=(__offsetof__ (reinterpret_cast <size_t> (&reinterpret_cast <char &> (static_cast<test *> (0)->a)))); } -- Summary: In C++, offsetof fails with constant member Product: gcc Version: 3.4.1 Status: UNCONFIRMED Severity: normal Priority: P1 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: jrh5y6virbl36ay at optonline dot net CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16618
next reply other threads:[~2004-07-18 17:36 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2004-07-18 17:36 jrh5y6virbl36ay at optonline dot net [this message] 2004-07-19 14:15 ` [Bug c++/16618] [3.4/3.5 regression] " bangerth at dealii dot org 2004-08-12 0:34 ` cvs-commit at gcc dot gnu dot org 2004-08-12 0:43 ` cvs-commit at gcc dot gnu dot org 2004-08-12 0:53 ` mmitchel at gcc dot gnu dot org
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=20040718173631.16618.jrh5y6virbl36ay@optonline.net \ --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).