From: Jason Merrill Date: Wed, 16 Apr 2025 20:02:09 +0000 (-0400) Subject: c++: constexpr virtual base diagnostic X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f0eccfd90370a7c5300f92493143c7e5a66be85;p=thirdparty%2Fgcc.git c++: constexpr virtual base diagnostic I thought this diagnostic could be clearer that the problem is the combination of virtual bases and constexpr constructor, not just complain that the class has virtual bases without context. gcc/cp/ChangeLog: * constexpr.cc (is_valid_constexpr_fn): Improve diagnostic. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/constexpr-dtor16.C: Adjust diagnostic. * g++.dg/cpp2a/constexpr-dynamic10.C: Likewise. --- diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 8a5b68c71fa..f56c5c42c82 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -307,7 +307,14 @@ is_valid_constexpr_fn (tree fun, bool complain) { ret = false; if (complain) - error ("%q#T has virtual base classes", DECL_CONTEXT (fun)); + { + if (DECL_CONSTRUCTOR_P (fun)) + error ("% constructor in %q#T that has " + "virtual base classes", DECL_CONTEXT (fun)); + else + error ("% destructor in %q#T that has " + "virtual base classes", DECL_CONTEXT (fun)); + } } return ret; diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-dtor16.C b/gcc/testsuite/g++.dg/cpp2a/constexpr-dtor16.C index b84aaf95b9d..99d13070571 100644 --- a/gcc/testsuite/g++.dg/cpp2a/constexpr-dtor16.C +++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-dtor16.C @@ -3,5 +3,5 @@ struct A { virtual ~A (); }; struct B : virtual A { constexpr ~B () {} }; -// { dg-error "'struct B' has virtual base classes" "" { target c++20 } .-1 } +// { dg-error "'constexpr' destructor in 'struct B' that has virtual base classes" "" { target c++20 } .-1 } // { dg-error "'constexpr' destructors only available with" "" { target c++17_down } .-2 } diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic10.C b/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic10.C index f9f82236d15..e543ce46b51 100644 --- a/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic10.C +++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic10.C @@ -5,7 +5,7 @@ struct C { virtual void a(); }; struct B { virtual void b(); }; -struct A : virtual B, C { virtual void c(); }; // { dg-error ".struct A. has virtual base classes" } +struct A : virtual B, C { virtual void c(); }; // { dg-error "virtual base classes" } constexpr A a; // { dg-error "call" }