This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/16618] New: In C++, offsetof fails with constant member
- From: "jrh5y6virbl36ay at optonline dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 18 Jul 2004 17:36:32 -0000
- Subject: [Bug c++/16618] New: In C++, offsetof fails with constant member
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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