The call to function f() in the test case below has undefined behavior because the array index is out of bounds. As a result, it is required to be diagnosed (according to [expr.const] of C++ 14). However, G++ silently accepts it. See also bug 82872 for a problem in a related area. #include <stddef.h> struct S { int i, a[1]; }; constexpr int f () { return offsetof (S, a[__PTRDIFF_MAX__ / 2]); } constexpr int i = f (); In contrast to the above, the following (also undefined) program is diagnosed as expected: #include <stddef.h> constexpr int f () { struct S { int a[1]; }; return offsetof (S, a[__PTRDIFF_MAX__]); } constexpr int i = f (); t.C:10:21: in constexpr expansion of ‘f()’ t.C:10:22: error: overflow in constant expression [-fpermissive] constexpr int i = f (); ^
See also bug 82877 for another similar problem.