[Bug c++/14932] [3.4/4.0 Regression] cannot use offsetof to get offsets of array elements in g++ 3.4.0 prerelease

scovich at gmail dot com gcc-bugzilla@gcc.gnu.org
Thu May 29 01:46:00 GMT 2014


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14932

Ryan Johnson <scovich at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |scovich at gmail dot com

--- Comment #16 from Ryan Johnson <scovich at gmail dot com> ---
A very similar problem arises with gcc-4.8.2 (and 4.9.0):

#include <stdio.h>
struct foo {
    char data[10];
};
int main() {
    int x = 4;
    printf("%zd\n", offsetof(struct foo, data[x]));
    return 0;
}


gcc-4.8.2 accepts it (with -xc), as does clang-3.0. In both cases, the
resulting binary prints "4" as expected. g++-4.8.2 rejects:

bug.cpp: In function ‘int main()’:
bug.cpp:9:47: error: ‘x’ cannot appear in a constant-expression
     printf("%zd\n", offsetof(struct foo, data[x]));

So again, I don't think this bug is fixed... but I'll happily file a new PR if
that's preferred.


More information about the Gcc-bugs mailing list