diff options
author | Jason Merrill <jason@redhat.com> | 2025-04-16 16:02:09 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2025-04-17 16:30:15 -0400 |
commit | 3f0eccfd90370a7c5300f92493143c7e5a66be85 (patch) | |
tree | 801aea02bb279a8513df3a973064b85896311d27 | |
parent | 3dabe6a53ef3ac24956938e2974d1c21a2a5c7ee (diff) | |
download | gcc-3f0eccfd90370a7c5300f92493143c7e5a66be85.zip gcc-3f0eccfd90370a7c5300f92493143c7e5a66be85.tar.gz gcc-3f0eccfd90370a7c5300f92493143c7e5a66be85.tar.bz2 |
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.
-rw-r--r-- | gcc/cp/constexpr.cc | 9 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp2a/constexpr-dtor16.C | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic10.C | 2 |
3 files changed, 10 insertions, 3 deletions
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 8a5b68c..f56c5c4 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 ("%<constexpr%> constructor in %q#T that has " + "virtual base classes", DECL_CONTEXT (fun)); + else + error ("%<constexpr%> 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 b84aaf9..99d1307 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 f9f8223..e543ce4 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" } |