https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82877
Bug ID: 82877 Summary: negative array index accepted in a pointer difference expression in constexpr context Product: gcc Version: 8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- The following invalid program is required to be diagnosed because it has undefined behavior due to the negative array index. However, it is silently accepted by G++. It is rejected with an error by Clang 5.0, Intel ICC 17, and Visual C++. constexpr int f () { struct S { int a[1]; }; S s = { 0 }; return &s.a[0] - &s.a[-1]; // undefined, should be rejected } constexpr int i = f ();