[Bug c++/14932] New: cannot use offsetof to get offsets of array elements in g++ 3.4.0 prerelease
bhelf at flitterfly dot whirpon dot com
gcc-bugzilla@gcc.gnu.org
Tue Apr 13 02:08:00 GMT 2004
In the gcc 3.4.0 prerelase, taking the offset of an array element works in gcc
but not in g++. This does work in 3.3.x and earlier versions of g++.
Version:
g++ (GCC) 3.4.0 20040407 (prerelease)
System:
i686-pc-linux-gnu Red Hat 9 AthlonXP
GCC Configuration:
/usr2/stow/gcc/3.4.0_prerelease/gcc-3.4.0-20040406/configure
--prefix=/usr2/stow/gcc/3.4.0_prerelease/ --enable-languages=c,c++
GCC Invocation:
/usr2/stow/gcc/3.4.0_prerelease/bin/g++ tt.c
GCC Output:
tt.c: In function `int main(int, char**)':
tt.c:16: error: an array reference cannot appear in a constant-expression
Testcase (unpreprocessed):
#include <stddef.h>
#ifdef __cplusplus
extern "C" int printf (__const char *__restrict __format, ...);
#endif
struct foobar
{
int bar;
int foo[22];
};
int main(int argc, char **argv)
{
printf("%u\n", (unsigned)offsetof(struct foobar, foo[12]));
}
Testcase (preprocessed):
# 1 "tt.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "tt.c"
# 1
"/usr2/stow/gcc/3.4.0_prerelease/bin/../lib/gcc/i686-pc-linux-gnu/3.4.0/include/stddef.h"
1 3 4
# 151
"/usr2/stow/gcc/3.4.0_prerelease/bin/../lib/gcc/i686-pc-linux-gnu/3.4.0/include/stddef.h"
3 4
typedef int ptrdiff_t;
# 213
"/usr2/stow/gcc/3.4.0_prerelease/bin/../lib/gcc/i686-pc-linux-gnu/3.4.0/include/stddef.h"
3 4
typedef unsigned int size_t;
# 3 "tt.c" 2
extern "C" int printf (__const char *__restrict __format, ...);
struct foobar
{
int bar;
int foo[22];
};
int main(int argc, char **argv)
{
printf("%u\n", (unsigned)(__offsetof__ (reinterpret_cast <size_t>
(&reinterpret_cast <char &> (static_cast<struct foobar *> (0)->foo[12])))));
}
--
Summary: cannot use offsetof to get offsets of array elements in
g++ 3.4.0 prerelease
Product: gcc
Version: 3.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: bhelf at flitterfly dot whirpon dot com
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=14932
More information about the Gcc-bugs
mailing list