public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: constexpr error with defaulted virtual dtor [PR93413]
@ 2022-11-03 12:33 Patrick Palka
  2022-11-03 15:50 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2022-11-03 12:33 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, Patrick Palka

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 an early exit added to mark_used by r181272 to defer synthesis of
virtual destructors until EOF where we can set their linkage.  This makes
them effectively unusable for constexpr evaluation since that needs to
be done immediately and can't also be deferred.

Fortunately, this early exit seems to no longer be necessary ever since
r208030 enabled us to tentatively set linkage of all defaulted virtual
destructors, including templated ones.  So this patch just gets rid of
this early exit.

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk?

	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                                  |  8 --------
 gcc/testsuite/g++.dg/cpp2a/constexpr-virtual21.C | 10 ++++++++++
 2 files changed, 10 insertions(+), 8 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/constexpr-virtual21.C

diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index e6779268ad4..eeb59eae64f 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -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
index 00000000000..8b70c5f538b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-virtual21.C
@@ -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;
-- 
2.38.1.381.gc03801e19c


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] c++: constexpr error with defaulted virtual dtor [PR93413]
  2022-11-03 12:33 [PATCH] c++: constexpr error with defaulted virtual dtor [PR93413] Patrick Palka
@ 2022-11-03 15:50 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2022-11-03 15:50 UTC (permalink / raw)
  To: Patrick Palka, gcc-patches

On 11/3/22 08:33, Patrick Palka wrote:
> 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 an early exit added to mark_used by r181272 to defer synthesis of
> virtual destructors until EOF where we can set their linkage.  This makes
> them effectively unusable for constexpr evaluation since that needs to
> be done immediately and can't also be deferred.
> 
> Fortunately, this early exit seems to no longer be necessary ever since
> r208030 enabled us to tentatively set linkage of all defaulted virtual
> destructors, including templated ones.  So this patch just gets rid of
> this early exit.
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk?

OK.

> 	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                                  |  8 --------
>   gcc/testsuite/g++.dg/cpp2a/constexpr-virtual21.C | 10 ++++++++++
>   2 files changed, 10 insertions(+), 8 deletions(-)
>   create mode 100644 gcc/testsuite/g++.dg/cpp2a/constexpr-virtual21.C
> 
> diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
> index e6779268ad4..eeb59eae64f 100644
> --- a/gcc/cp/decl2.cc
> +++ b/gcc/cp/decl2.cc
> @@ -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
> index 00000000000..8b70c5f538b
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-virtual21.C
> @@ -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;


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-03 15:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-03 12:33 [PATCH] c++: constexpr error with defaulted virtual dtor [PR93413] Patrick Palka
2022-11-03 15:50 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).