[Bug c++/16868] New: [3.4 regression] offsetof fails with array member

ppluzhnikov at charter dot net gcc-bugzilla@gcc.gnu.org
Wed Aug 4 00:15:00 GMT 2004


The test case below fails with

off.cc: In function `int main()':
off.cc:11: error: an array reference cannot appear in a constant-expression

This is possibly a variant of bug 16681 "offsetof fails with constant member"

This used to work in g++-2.95.x and g++-3.3.x
In C-mode the test case compiles fine with all versions tested.

--- cut ---
#include <stddef.h>

typedef struct Foo {
    int x[2];
} FOO;


int main()
{
    size_t a = offsetof(FOO, x);    // ok
    size_t b = offsetof(FOO, x[1]); // fails with gcc-3.4.0
    return 0;
}
--- cut ---

-- 
           Summary: [3.4 regression] offsetof fails with array member
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ppluzhnikov at charter 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=16868



More information about the Gcc-bugs mailing list