https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116568
Nathaniel Shead <nshead at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|--- |15.0 Assignee|unassigned at gcc dot gnu.org |nshead at gcc dot gnu.org --- Comment #4 from Nathaniel Shead <nshead at gcc dot gnu.org> --- The ICE is fixed, though the mangling is not correct yet. This is because of uncertainties around how exactly to handle mangling lambdas in alias templates (and member template instantiations in general). Linked is a patch I'd written initially to try to support mangling the alias case for if this gets picked up again later: https://gcc.gnu.org/pipermail/gcc-patches/2025-January/672683.html Additionally, here's a (largely untested) patch to force such lambdas to be considered TU-local despite not fulfilling the requirements given in the standard to be as such: diff --git a/gcc/cp/lambda.cc b/gcc/cp/lambda.cc index 5593636eaf8..dbef1be3e5e 100644 --- a/gcc/cp/lambda.cc +++ b/gcc/cp/lambda.cc @@ -1575,6 +1575,15 @@ record_lambda_scope (tree lambda) } } + /* A class-scope lambda in a member template should not have a + mangling scope. */ + tree ctx = TYPE_CONTEXT (closure); + if (scope + && ctx + && CLASS_TYPE_P (ctx) + && current_template_depth > template_class_depth (ctx)) + scope = NULL_TREE; + LAMBDA_EXPR_EXTRA_SCOPE (lambda) = scope; if (scope) maybe_key_decl (scope, TYPE_NAME (closure)); diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index c89834c1abd..7416aec5441 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -13439,12 +13439,9 @@ depset::hash::is_tu_local_entity (tree decl, bool explain/*=false*/) && !(UNSCOPED_ENUM_P (type) && TYPE_VALUES (type))) { tree main_decl = TYPE_MAIN_DECL (type); - if (!DECL_CLASS_SCOPE_P (main_decl) - && !decl_function_context (main_decl) - /* LAMBDA_EXPR_EXTRA_SCOPE will be set for lambdas defined in - contexts where they would not be TU-local. */ - && !(LAMBDA_TYPE_P (type) - && LAMBDA_TYPE_EXTRA_SCOPE (type))) + if (LAMBDA_TYPE_P (type) + ? !LAMBDA_TYPE_EXTRA_SCOPE (type) + : !(DECL_CLASS_SCOPE_P (main_decl) || decl_function_context (main_decl))) { if (explain) inform (loc, "%qT has no name and is not defined within a class, "