public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: Overeager use of deleted function before ADL [PR68942]
@ 2021-04-28 19:03 Patrick Palka
  2021-04-29 13:46 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2021-04-28 19:03 UTC (permalink / raw)
  To: gcc-patches

Here, at template definition time, ordinary name lookup for 'foo(t)'
finds the deleted function, and so we form a CALL_EXPR thereof.  Later
at instantiation time, when initially substituting into this CALL_EXPR
with T=N::A, we end up calling mark_used on this deleted function before
we augment the overload set via ADL and select the right function.

This patch fixes this issue by using tf_conv in order to disable
mark_used during the initial substitution of the function of a CALL_EXPR
when KOENIG_P.

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

gcc/cp/ChangeLog:

	PR c++/68942
	* pt.c (tsubst_copy_and_build) <case CALL_EXPR>: When KOENIG_P,
	add tf_conv to complain during the initial substitution into
	the function.

gcc/testsuite/ChangeLog:

	PR c++/68942
	* g++.dg/template/koenig12.C: New test.
---
 gcc/cp/pt.c                              |  6 +++++-
 gcc/testsuite/g++.dg/template/koenig12.C | 15 +++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/template/koenig12.C

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index d79fecd4949..bed9a22193a 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -20238,7 +20238,11 @@ tsubst_copy_and_build (tree t,
 	      /* Avoid error about taking the address of a constructor.  */
 	      function = TREE_OPERAND (function, 0);
 
-	    function = tsubst_copy_and_build (function, args, complain,
+	    /* When KOENIG_P, we don't want to mark_used a function until
+	       after performing ADL, during this substitution we disable
+	       mark_used by adding tf_conv to complain (68942).  */
+	    function = tsubst_copy_and_build (function, args,
+					      complain | (koenig_p * tf_conv),
 					      in_decl,
 					      !qualified_p,
 					      integral_constant_expression_p);
diff --git a/gcc/testsuite/g++.dg/template/koenig12.C b/gcc/testsuite/g++.dg/template/koenig12.C
new file mode 100644
index 00000000000..fd05ef5719e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/koenig12.C
@@ -0,0 +1,15 @@
+// PR c++/68942
+// { dg-do compile { target c++11 } }
+
+void foo(...) = delete;
+
+template <class T> void lookup(T t) { foo(t); }
+
+namespace N {
+ struct A { };
+ int foo(A);
+}
+
+int main() {
+  lookup(N::A{});
+}
-- 
2.31.1.362.g311531c9de


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

* Re: [PATCH] c++: Overeager use of deleted function before ADL [PR68942]
  2021-04-28 19:03 [PATCH] c++: Overeager use of deleted function before ADL [PR68942] Patrick Palka
@ 2021-04-29 13:46 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2021-04-29 13:46 UTC (permalink / raw)
  To: Patrick Palka, gcc-patches

On 4/28/21 3:03 PM, Patrick Palka wrote:
> Here, at template definition time, ordinary name lookup for 'foo(t)'
> finds the deleted function, and so we form a CALL_EXPR thereof.  Later
> at instantiation time, when initially substituting into this CALL_EXPR
> with T=N::A, we end up calling mark_used on this deleted function before
> we augment the overload set via ADL and select the right function.
> 
> This patch fixes this issue by using tf_conv in order to disable
> mark_used during the initial substitution of the function of a CALL_EXPR
> when KOENIG_P.
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk?

Hmm, I suppose this is close enough to the tf_conv case to make sense, 
as we're still figuring out which functions are candidates.  OK.

> gcc/cp/ChangeLog:
> 
> 	PR c++/68942
> 	* pt.c (tsubst_copy_and_build) <case CALL_EXPR>: When KOENIG_P,
> 	add tf_conv to complain during the initial substitution into
> 	the function.
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR c++/68942
> 	* g++.dg/template/koenig12.C: New test.
> ---
>   gcc/cp/pt.c                              |  6 +++++-
>   gcc/testsuite/g++.dg/template/koenig12.C | 15 +++++++++++++++
>   2 files changed, 20 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/g++.dg/template/koenig12.C
> 
> diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
> index d79fecd4949..bed9a22193a 100644
> --- a/gcc/cp/pt.c
> +++ b/gcc/cp/pt.c
> @@ -20238,7 +20238,11 @@ tsubst_copy_and_build (tree t,
>   	      /* Avoid error about taking the address of a constructor.  */
>   	      function = TREE_OPERAND (function, 0);
>   
> -	    function = tsubst_copy_and_build (function, args, complain,
> +	    /* When KOENIG_P, we don't want to mark_used a function until
> +	       after performing ADL, during this substitution we disable
> +	       mark_used by adding tf_conv to complain (68942).  */
> +	    function = tsubst_copy_and_build (function, args,
> +					      complain | (koenig_p * tf_conv),
>   					      in_decl,
>   					      !qualified_p,
>   					      integral_constant_expression_p);
> diff --git a/gcc/testsuite/g++.dg/template/koenig12.C b/gcc/testsuite/g++.dg/template/koenig12.C
> new file mode 100644
> index 00000000000..fd05ef5719e
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/template/koenig12.C
> @@ -0,0 +1,15 @@
> +// PR c++/68942
> +// { dg-do compile { target c++11 } }
> +
> +void foo(...) = delete;
> +
> +template <class T> void lookup(T t) { foo(t); }
> +
> +namespace N {
> + struct A { };
> + int foo(A);
> +}
> +
> +int main() {
> +  lookup(N::A{});
> +}
> 


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

end of thread, other threads:[~2021-04-29 13:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-28 19:03 [PATCH] c++: Overeager use of deleted function before ADL [PR68942] Patrick Palka
2021-04-29 13:46 ` 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).