Works in 10.3, broken in 11.1 till trunk. https://godbolt.org/z/x3z6WYroE
auto f = [](auto &&m) { enum { _,e3,e2,e1,C4,C3,C2,C1 }; static constexpr int x_coeffs[3][4] = { {e1,C2,C3,C4}, {e2,C1,C3,C4}, {e3,C1,C2,C4}, }; }; int main() { f(0); } <source>: In instantiation of '<lambda(auto:1&&)> [with auto:1 = int]': <source>:11:6: required from here <source>:4:10: internal compiler error: in tsubst_copy, at cp/pt.cc:16910 4 | {e1,C2,C3,C4}, | ^~
Confirmed. Started with r11-7993-g9f4c41147a41d0
Looking into it..
The patch above changed - 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)) but here current_nonlambda_scope () is ::, a NAMESPACE_DECL, which doesn't have a type, so is considered type-dependent. So we don't call tsubst_enum. That doesn't look right.
(In reply to Marek Polacek from comment #4) > The patch above changed > > - 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)) > > but here current_nonlambda_scope () is ::, a NAMESPACE_DECL, which doesn't > have a type, so is considered type-dependent. So we don't call tsubst_enum. > That doesn't look right. Whoops, sorry Marek, didn't know you were already looking into this. Your analysis makes sense to me :)
Testing a fix.
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>: https://gcc.gnu.org/g:409edcca331296b53842c50d3b789e1b1ccc05e5 commit r12-8290-g409edcca331296b53842c50d3b789e1b1ccc05e5 Author: Marek Polacek <polacek@redhat.com> Date: Tue Apr 26 16:12:58 2022 -0400 c++: enum in generic lambda at global scope [PR105398] We crash compiling this test since r11-7993 which changed lookup_template_class_1 so that we only call tsubst_enum when !uses_template_parms (current_nonlambda_scope ()) But here current_nonlambda_scope () is the global NAMESPACE_DECL ::, which doesn't have a type, therefore is considered type-dependent. So we don't call tsubst_enum, and crash in tsubst_copy/CONST_DECL because we didn't find the e1 enumerator. I don't think any namespace can depend on any template parameter, so this patch tweaks uses_template_parms. PR c++/105398 gcc/cp/ChangeLog: * pt.cc (uses_template_parms): Return false for any NAMESPACE_DECL. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/lambda-generic-enum2.C: New test.
Fixed on trunk so far, will backport to 11.4.
The releases/gcc-11 branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>: https://gcc.gnu.org/g:3a1358e5f38864bf5688a7b6db1fda482321a77a commit r11-9941-g3a1358e5f38864bf5688a7b6db1fda482321a77a Author: Marek Polacek <polacek@redhat.com> Date: Tue Apr 26 16:12:58 2022 -0400 c++: enum in generic lambda at global scope [PR105398] We crash compiling this test since r11-7993 which changed lookup_template_class_1 so that we only call tsubst_enum when !uses_template_parms (current_nonlambda_scope ()) But here current_nonlambda_scope () is the global NAMESPACE_DECL ::, which doesn't have a type, therefore is considered type-dependent. So we don't call tsubst_enum, and crash in tsubst_copy/CONST_DECL because we didn't find the e1 enumerator. I don't think any namespace can depend on any template parameter, so this patch tweaks uses_template_parms. PR c++/105398 gcc/cp/ChangeLog: * pt.c (uses_template_parms): Return false for any NAMESPACE_DECL. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/lambda-generic-enum2.C: New test. (cherry picked from commit 409edcca331296b53842c50d3b789e1b1ccc05e5)
Fixed.