c++: dependence of baselink [PR105964]
authorJason Merrill <jason@redhat.com>
Wed, 22 Jun 2022 22:19:11 +0000 (18:19 -0400)
committerJason Merrill <jason@redhat.com>
Thu, 23 Jun 2022 03:46:32 +0000 (23:46 -0400)
helper<token>::c isn't dependent just because we haven't deduced its return
type yet.  type_dependent_expression_p already knows how to deal with that
for bare FUNCTION_DECL, but needs to learn to look through a BASELINK.

PR c++/105964

gcc/cp/ChangeLog:

* pt.cc (type_dependent_expression_p): Look through BASELINK.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/nontype-auto21.C: New test.

gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp1z/nontype-auto21.C [new file with mode: 0644]

index 214ad84..6723800 100644 (file)
@@ -27892,6 +27892,15 @@ type_dependent_expression_p (tree expression)
       && DECL_INITIAL (expression))
    return true;
 
+  /* Pull a FUNCTION_DECL out of a BASELINK if we can.  */
+  if (BASELINK_P (expression))
+    {
+      if (BASELINK_OPTYPE (expression)
+         && dependent_type_p (BASELINK_OPTYPE (expression)))
+       return true;
+      expression = BASELINK_FUNCTIONS (expression);
+    }
+
   /* A function or variable template-id is type-dependent if it has any
      dependent template arguments.  */
   if (VAR_OR_FUNCTION_DECL_P (expression)
diff --git a/gcc/testsuite/g++.dg/cpp1z/nontype-auto21.C b/gcc/testsuite/g++.dg/cpp1z/nontype-auto21.C
new file mode 100644 (file)
index 0000000..376d632
--- /dev/null
@@ -0,0 +1,20 @@
+// PR c++/105964
+// { dg-do compile { target c++17 } }
+
+struct token {};
+
+struct example {};
+
+template< typename >
+struct helper
+{
+    static constexpr auto c() { return 42; }
+};
+
+struct impostor_c
+{
+    template< typename T, auto= helper< T >::c >
+    static example func();
+};
+
+example c= impostor_c::func< token >();