public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Patrick Palka <ppalka@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-5373] c++: template-id ADL and partial instantiation [PR99911]
Date: Thu, 18 Nov 2021 15:05:47 +0000 (GMT)	[thread overview]
Message-ID: <20211118150547.D12AB385802D@sourceware.org> (raw)

https://gcc.gnu.org/g:90de06a7b3ce6ae8381136e58a2dde91fbbb6eff

commit r12-5373-g90de06a7b3ce6ae8381136e58a2dde91fbbb6eff
Author: Patrick Palka <ppalka@redhat.com>
Date:   Thu Nov 18 10:05:13 2021 -0500

    c++: template-id ADL and partial instantiation [PR99911]
    
    Here when partially instantiating the call get<U>(T{}) with T=N::A
    (for which earlier unqualified name lookup for 'get' found nothing)
    the arguments after substitution are no longer dependent but the callee
    still is, so perform_koenig_lookup postpones ADL.  But then we go on to
    diagnose the unresolved template name anyway, as if ADL was already
    performed and failed.
    
    This patch fixes this by avoiding the error path in question when the
    template arguments of an unresolved template-id are still dependent,
    mirroring the dependence check in perform_koenig_lookup.
    
            PR c++/99911
    
    gcc/cp/ChangeLog:
    
            * pt.c (tsubst_copy_and_build) <case CALL_EXPR>: Don't diagnose
            name lookup failure if the arguments to an unresolved template
            name are still dependent.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp2a/fn-template24.C: New test.

Diff:
---
 gcc/cp/pt.c                                |  4 +++-
 gcc/testsuite/g++.dg/cpp2a/fn-template24.C | 16 ++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 2e31663c277..ad51c07347b 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -20434,7 +20434,9 @@ tsubst_copy_and_build (tree t,
 	if (function != NULL_TREE
 	    && (identifier_p (function)
 		|| (TREE_CODE (function) == TEMPLATE_ID_EXPR
-		    && identifier_p (TREE_OPERAND (function, 0))))
+		    && identifier_p (TREE_OPERAND (function, 0))
+		    && !any_dependent_template_arguments_p (TREE_OPERAND
+							    (function, 1))))
 	    && !any_type_dependent_arguments_p (call_args))
 	  {
 	    if (TREE_CODE (function) == TEMPLATE_ID_EXPR)
diff --git a/gcc/testsuite/g++.dg/cpp2a/fn-template24.C b/gcc/testsuite/g++.dg/cpp2a/fn-template24.C
new file mode 100644
index 00000000000..b444ac6a273
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/fn-template24.C
@@ -0,0 +1,16 @@
+// PR c++/99911
+// { dg-do compile { target c++20 } }
+
+namespace N {
+  struct A { };
+  template<class T> void get(A);
+};
+
+template<class T>
+auto f() {
+  return []<class U>(U) { get<U>(T{}); };
+}
+
+int main() {
+  f<N::A>()(0);
+}


                 reply	other threads:[~2021-11-18 15:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211118150547.D12AB385802D@sourceware.org \
    --to=ppalka@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).