From: Patrick Palka Date: Thu, 29 Apr 2021 17:43:00 +0000 (-0400) Subject: c++: Overeager use of deleted function before ADL [PR68942] X-Git-Tag: upstream/12.2.0~8402 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=efeca0ac4155b76ce713155f190422aac20537c5;p=platform%2Fupstream%2Fgcc.git c++: Overeager use of deleted function before ADL [PR68942] Here, at template definition time, ordinary name lookup for 'foo(t)' finds only 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 (since it's the only function in the overload set), triggering a bogus "use of deleted function error", before we get to augment the overload set via ADL. This patch fixes this issue by using the tf_conv flag to disable mark_used during the initial substitution into the callee of a CALL_EXPR when KOENIG_P, since at this point we're still figuring out which functions are candidates. gcc/cp/ChangeLog: PR c++/68942 * pt.c (tsubst_copy_and_build) : When KOENIG_P, set tf_conv during the initial substitution into the function. gcc/testsuite/ChangeLog: PR c++/68942 * g++.dg/template/koenig12.C: New test. --- diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index eaf46659f85..4e9b40f2164 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -20232,7 +20232,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 the callee before + augmenting the overload set via ADL, so during this initial + substitution we disable mark_used by setting tf_conv (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 void lookup(T t) { foo(t); } + +namespace N { + struct A { }; + int foo(A); +} + +int main() { + lookup(N::A{}); +}