>Class: rejects-legal >Release: gcc (GCC) 4.2.3 >Description: like bug 14932 - 4.2.3 c++ does not allow variable array index in macro offsetof
it looks like offsetof maps to a builtin function: #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER) This appears to be in contravention of ISO/IEC 14882:1998 17.4.1.2 para 5: "Names which are defined as macros in C shall be defined as macros in the C++ Standard Library, even if C grants license for implementation as functions. [Note: the names defined as macros in C include the following: assert, errno, offsetof, setjump, va_arg, va_end and va_start. -end note]" >How-To-Repeat: #include <cstddef> struct A { int array[10]; }; std::size_t off(int x) { return offsetof(struct A, array[x]); } $ g++ offsetof.cc -S offsetof.cc: In function 'size_t off(int)': offsetof.cc:7: error: 'x' cannot appear in a constant-expression $ cat offsetof.s .file "offsetof.cc" >Fix: use a macro (as mandated for c++) - e.g. /usr/include/iso/stddef_iso.h: #define offsetof(s, m) (std::size_t)(&(((s *)0)->m)) -- Summary: offsetof defined as function in contravention of ISO/IEC 14882:1998 17.4.1.2 para 5 Product: gcc Version: 4.2.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: ajrobb at bigfoot dot com GCC build triplet: i386-pc-solaris2.10 GCC host triplet: i386-pc-solaris2.10 GCC target triplet: i386-pc-solaris2.10 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36549