https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89331
Jason Merrill <jason at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |ASSIGNED Assignee|unassigned at gcc dot gnu.org |jason at gcc dot gnu.org --- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> --- (In reply to Stas Sergeev from comment #2) > (In reply to Jakub Jelinek from comment #1) > > Simplified testcase: > > struct A { char a; }; > > struct B : public A { static constexpr int b = __builtin_offsetof (B, a); }; > > > > clang rejects this too, not really sure if it is valid or not. > > Thanks for taking a look! > A slight off-topic: any idea why even this rejects: > struct A { > char a; > static constexpr int b = __builtin_offsetof (A, a); > }; > > and is there any work-around when I want to > pass offsetof value into a template non-type, > which also rejects: > struct A { > char a; > B<__builtin_offsetof(A, a)> b; > }; > > Does the standard explicitly forbids that, of just gcc? The standard says that for a standard-layout class, the address of the first member is the same as the address of the class, so offsetof(A,a) will be 0. But when we're in the middle of the class definition we don't know yet whether it's standard-layout, so we can't answer yet. A compiler is allowed to reorder fields of a non-standard-layout class.