]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: generic lambda, local class, __func__ [PR108242]
authorJason Merrill <jason@redhat.com>
Thu, 16 Mar 2023 19:11:25 +0000 (15:11 -0400)
committerJason Merrill <jason@redhat.com>
Tue, 18 Apr 2023 20:44:27 +0000 (16:44 -0400)
Here we are trying to do name lookup in a deferred instantiation of t() and
failing to find __func__.  tsubst_expr already tries to instantiate members
of local classes, but was failing with the partial instantiation of generic
lambdas.

PR c++/108242

gcc/cp/ChangeLog:

* pt.cc (tsubst_expr) [TAG_DEFN]: Handle partial instantiation.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1y/lambda-generic-func2.C: New test.

gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp1y/lambda-generic-func2.C [new file with mode: 0644]

index 4d6c6bfb8cf64d0dc14812a22996e0efee8482a0..a9c57e5d45a70560c4aff11c614f3d214d87496b 100644 (file)
@@ -19090,7 +19090,10 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl,
 
     case TAG_DEFN:
       tmp = tsubst (TREE_TYPE (t), args, complain, NULL_TREE);
-      if (CLASS_TYPE_P (tmp))
+      if (dependent_type_p (tmp))
+       /* This is a partial instantiation, try again when full.  */
+       add_stmt (build_min (TAG_DEFN, tmp));
+      else if (CLASS_TYPE_P (tmp))
        {
          /* Local classes are not independent templates; they are
             instantiated along with their containing function.  And this
diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-func2.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-func2.C
new file mode 100644 (file)
index 0000000..ed541c7
--- /dev/null
@@ -0,0 +1,18 @@
+// PR c++/108242
+// { dg-do compile { target c++14 } }
+
+template<int F>
+void my_fun()
+{
+    [&](auto) {
+        static constexpr char const* fun_name = __func__;
+        struct t
+        {
+            t() { fun_name; };
+        } t1;
+    }(12);
+}
+
+int main() {
+    my_fun<1>();
+}