]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: constexpr error with defaulted virtual dtor [PR93413]
authorPatrick Palka <ppalka@redhat.com>
Thu, 3 Nov 2022 18:55:35 +0000 (14:55 -0400)
committerPatrick Palka <ppalka@redhat.com>
Thu, 3 Nov 2022 18:55:35 +0000 (14:55 -0400)
We're rejecting the below testcase with

  error: 'virtual constexpr Base::~Base()' used before its definition
  error: 'virtual constexpr Derived::~Derived()' used before its definition

due to special handling in mark_used added by r181272 to defer synthesis
of virtual destructors until EOF (where we can set their linkage), which
in turn makes them effectively unusable during constexpr evaluation.

Fortunately it seems this special handling is unnecessary ever since
r208030 enabled us to tentatively set linkage of all defaulted virtual
destructors, including templated ones.  So this patch gets rid of this
special handling.

PR c++/93413

gcc/cp/ChangeLog:

* decl2.cc (mark_used): Don't defer synthesis of virtual
functions.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/constexpr-virtual21.C: New test.

gcc/cp/decl2.cc
gcc/testsuite/g++.dg/cpp2a/constexpr-virtual21.C [new file with mode: 0644]

index e6779268ad42145ab01516a9712705ac7e6bf9f2..eeb59eae64f901dc0c1c653f6d81f29bb803d62d 100644 (file)
@@ -5788,14 +5788,6 @@ mark_used (tree decl, tsubst_flags_t complain /* = tf_warning_or_error */)
       && !DECL_DEFAULTED_OUTSIDE_CLASS_P (decl)
       && ! DECL_INITIAL (decl))
     {
-      /* Defer virtual destructors so that thunks get the right
-        linkage.  */
-      if (DECL_VIRTUAL_P (decl) && !at_eof)
-       {
-         note_vague_linkage_fn (decl);
-         return true;
-       }
-
       /* Remember the current location for a function we will end up
         synthesizing.  Then we can inform the user where it was
         required in the case of error.  */
diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-virtual21.C b/gcc/testsuite/g++.dg/cpp2a/constexpr-virtual21.C
new file mode 100644 (file)
index 0000000..8b70c5f
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/93413
+// { dg-do compile { target c++20 } }
+
+struct Base {
+  virtual ~Base() = default;
+};
+constexpr Base b;
+
+struct Derived : Base { };
+constexpr Derived d;