https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96286
Bug ID: 96286 Summary: Unhelpful errors after a failed static_assert Product: gcc Version: 10.1.1 Status: UNCONFIRMED Keywords: diagnostic Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Target Milestone: --- template<typename T> struct S { static_assert( sizeof(T) < 4, "smol" ); char* p = new char[3 - sizeof(T)]; }; S<long long> s; GCC gives two errors: sa.C: In instantiation of ‘struct S<long long int>’: sa.C:9:14: required from here sa.C:4:28: error: static assertion failed: smol 4 | static_assert( sizeof(T) < 4, "smol" ); | ~~~~~~~~~~^~~ sa.C: In instantiation of ‘constexpr S<long long int>::S()’: sa.C:9:14: required from here sa.C:6:24: error: size ‘18446744073709551611’ of array exceeds maximum object size ‘9223372036854775807’ 6 | char* p = new char[3 - sizeof(T)]; | ~~^~~~~~~~~~~ The second error is unhelpful. I know the array size is invalid, that's why I put the static assertion there. Clang just says: sa.C:4:3: error: static_assert failed due to requirement 'sizeof(long long) < 4' "smol" static_assert( sizeof(T) < 4, "smol" ); ^ ~~~~~~~~~~~~~ sa.C:9:14: note: in instantiation of template class 'S<long long>' requested here S<long long> s; ^ 1 error generated. EDG says: "sa.C", line 4: error: static assertion failed with "smol" static_assert( sizeof(T) < 4, "smol" ); ^ detected during instantiation of class "S<T> [with T=long long]" at line 9 1 error detected in the compilation of "sa.C".