https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113804
Bug ID: 113804
Summary: offsetof(type, array[run_time_value]) failing
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jlame646 at gmail dot com
Target Milestone: ---
The following code starts failing in gcc but is accepted by clang and msvc.
```
#include <cstddef>
struct type {
int array[4];
};
int main(int argc, char**) {
return offsetof(type, array[argc]);
}
```
GCC says:
```
In file included from
/opt/compiler-explorer/gcc-trunk-20240207/include/c++/14.0.1/cstddef:50,
from <source>:1:
<source>: In function 'int main(int, char**)':
<source>:8:33: error: 'argc' is not a constant expression
8 | return offsetof(type, array[argc]);
|
```