]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: template-id ADL and partial instantiation [PR99911]
authorPatrick Palka <ppalka@redhat.com>
Thu, 18 Nov 2021 15:05:13 +0000 (10:05 -0500)
committerPatrick Palka <ppalka@redhat.com>
Thu, 18 Nov 2021 15:05:13 +0000 (10:05 -0500)
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.

gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp2a/fn-template24.C [new file with mode: 0644]

index 2e31663c277bd98f9a38f832f4c48109be11b470..ad51c07347b543f535c7023971df63f5b0dcb457 100644 (file)
@@ -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 (file)
index 0000000..b444ac6
--- /dev/null
@@ -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);
+}