]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: constexpr virtual base diagnostic
authorJason Merrill <jason@redhat.com>
Wed, 16 Apr 2025 20:02:09 +0000 (16:02 -0400)
committerJason Merrill <jason@redhat.com>
Thu, 17 Apr 2025 20:30:15 +0000 (16:30 -0400)
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.

gcc/cp/constexpr.cc
gcc/testsuite/g++.dg/cpp2a/constexpr-dtor16.C
gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic10.C

index 8a5b68c71fafa7a24bb0fe7f739f6b46d81a47ec..f56c5c42c82185ee29b5d699081d1587fcd65099 100644 (file)
@@ -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;
index b84aaf95b9d0678c6bb5b55270ecf0d9caf626d9..99d1307057137c7e3a1d04b37c95421833e3fca7 100644 (file)
@@ -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 }
index f9f82236d15f9ad540013f4b1079b4ac5abf3520..e543ce46b5182d303a8449bc8d121369d788115c 100644 (file)
@@ -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" }