On Tue, 26 Apr 2022, Marek Polacek via Gcc-patches wrote:
> 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.
>
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/11?
>
> 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.
> ---
> gcc/cp/pt.cc | 2 +-
> gcc/testsuite/g++.dg/cpp1y/lambda-generic-enum2.C | 15 +++++++++++++++
> 2 files changed, 16 insertions(+), 1 deletion(-)
> create mode 100644 gcc/testsuite/g++.dg/cpp1y/lambda-generic-enum2.C
>
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index 3cf1d7af8d2..e785c5db142 100644
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -10905,7 +10905,7 @@ uses_template_parms (tree t)
> || uses_template_parms (TREE_CHAIN (t)));
> else if (TREE_CODE (t) == TYPE_DECL)
> dependent_p = dependent_type_p (TREE_TYPE (t));
> - else if (t == error_mark_node)
> + else if (t == error_mark_node || TREE_CODE (t) == NAMESPACE_DECL)
LGTM. In passing, perhaps we should move this t == error_mark_node test
to the beginning of the function alongside the t == NULL_TREE test?
> dependent_p = false;
> else
> dependent_p = instantiation_dependent_expression_p (t);
> diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-enum2.C
> b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-enum2.C
> new file mode 100644
> index 00000000000..77cf0bb9d02
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-enum2.C
> @@ -0,0 +1,15 @@
> +// PR c++/105398
> +// { dg-do compile { target c++14 } }
> +
> +auto f = [](auto &&m) {
> + enum E { _,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);
> +}
>
> base-commit: 9ace5d4dab2ab39072b0f07089621a823580f27c
> --
> 2.35.1
>
>