https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92193
Bug ID: 92193 Summary: Poor diagnostics when a constexpr function call follows a failed static_assert Product: gcc Version: 10.0 Status: UNCONFIRMED Keywords: diagnostic Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org CC: jason at gcc dot gnu.org Target Milestone: --- If we compile this with NO_CONSTEXPR the diagnostic is fine: template<typename T> struct has_foo { static constexpr bool value = false; }; template<typename T> #ifndef NO_CONSTEXPR constexpr #endif bool foo(T t) noexcept(noexcept(t.foo())) { return t.foo(); } template<typename T> void maybe_foo(T t) { static_assert( has_foo<T>::value, "has foo" ); foo(t); } struct X { }; int main() { X x; maybe_foo(x); } ce.cc: In instantiation of ‘void maybe_foo(T) [with T = X]’: ce.cc:26:14: required from here ce.cc:17:20: error: static assertion failed: has foo static_assert( has_foo<T>::value, "has foo" ); ^~~~~~~~~~ However, when the function is constexpr the output is much worse: ce.cc: In instantiation of ‘void maybe_foo(T) [with T = X]’: ce.cc:23:14: required from here ce.cc:14:20: error: static assertion failed: has foo static_assert( has_foo<T>::value, "has foo" ); ^~~~~~~~~~ ce.cc: In instantiation of ‘constexpr bool foo(T) [with T = X]’: ce.cc:15:8: required from ‘void maybe_foo(T) [with T = X]’ ce.cc:23:14: required from here ce.cc:7:32: error: ‘struct X’ has no member named ‘foo’ foo(T t) noexcept(noexcept(t.foo())) ~~^~~ ce.cc: In instantiation of ‘constexpr bool foo(T) [with T = X]’: ce.cc:15:8: required from ‘void maybe_foo(T) [with T = X]’ ce.cc:23:14: required from here ce.cc:7:32: error: ‘struct X’ has no member named ‘foo’ ce.cc:8:14: error: ‘struct X’ has no member named ‘foo’ { return t.foo(); } ~~^~~ The errors following the static assertion are not useful. The static_assert is there precisely to make compilation fail, but it doesn't stop errors being produced from the constexpr function that follows it (even though we're in a non-constexpr function). This affects libstdc++ because adding 'constexpr' throughout the library means that suddenly we get loads more errors in the testsuite and need to tell dejagnu to ignore them.