Here we weren't instantiating the enumerators because the arglist still had
the template parameter for the generic lambda, so looking one up failed.  We
need to instantiate if the non-lambda enclosing scope is non-dependent.

Tested x86_64-pc-linux-gnu, applying to trunk.

gcc/cp/ChangeLog:

        PR c++/95317
        * pt.c (lookup_template_class_1): Do tsubst_enum when
        tsubsting a generic lambda.

gcc/testsuite/ChangeLog:

        PR c++/95317
        * g++.dg/cpp1y/lambda-generic-enum1.C: New test.
---
 gcc/cp/pt.c                                       |  3 ++-
 gcc/testsuite/g++.dg/cpp1y/lambda-generic-enum1.C | 10 ++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp1y/lambda-generic-enum1.C

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index d6a8ede386d..41bc633cfce 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -10173,7 +10173,8 @@ lookup_template_class_1 (tree d1, tree arglist, tree 
in_decl, tree context,
        = tree_cons (arglist, t,
                     DECL_TEMPLATE_INSTANTIATIONS (found));
 
-      if (TREE_CODE (template_type) == ENUMERAL_TYPE && !is_dependent_type
+      if (TREE_CODE (template_type) == ENUMERAL_TYPE
+         && !uses_template_parms (current_nonlambda_scope ())
          && !DECL_ALIAS_TEMPLATE_P (gen_tmpl))
        /* Now that the type has been registered on the instantiations
           list, we set up the enumerators.  Because the enumeration
diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-enum1.C 
b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-enum1.C
new file mode 100644
index 00000000000..de15443bfcf
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-enum1.C
@@ -0,0 +1,10 @@
+// PR c++/95317
+// { dg-do compile { target c++14 } }
+
+template <typename> void fn1() {
+  [](auto) {
+    enum { VALUE };
+    VALUE;
+  };
+}
+int main() { fn1<void>; }

base-commit: 7ebdef2076fda56cb4cffb941f6c2576f980f3b3
prerequisite-patch-id: 22fd889eedb29aa662bdfc0fcc38e7a1072b47b4
-- 
2.27.0

Reply via email to