https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98533
--- Comment #16 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
If the presence in TYPE_FIELDS is desirable, perhaps either we should repeat
fixup_type_variants (or just update TYPE_FIELDS on all variants manually) in
the
if (--parser->num_classes_being_defined == 0)
block.
Like following which fixes the ICE.
Perhaps we could turn those all if (class_type != whatever) blocks into a
lambda
taking whatever as argument so that we don't duplicate the code in so many
spots.
--- gcc/cp/parser.cc.jj 2025-02-27 22:04:36.007028112 +0100
+++ gcc/cp/parser.cc 2025-03-05 21:10:16.781237628 +0100
@@ -27718,6 +27718,7 @@ cp_parser_class_specifier (cp_parser* pa
{
tree decl;
tree class_type = NULL_TREE;
+ tree class_type_fields = NULL_TREE;
tree pushed_scope = NULL_TREE;
unsigned ix;
cp_default_arg_entry *e;
@@ -27748,9 +27749,14 @@ cp_parser_class_specifier (cp_parser* pa
take care of them now. */
if (class_type != e->class_type)
{
+ /* cp_parser_late_parsing_default_args could have changed
+ TYPE_FIELDS (class_type). */
+ if (class_type && TYPE_FIELDS (class_type) != class_type_fields)
+ fixup_type_variants (class_type);
if (pushed_scope)
pop_scope (pushed_scope);
class_type = e->class_type;
+ class_type_fields = TYPE_FIELDS (class_type);
pushed_scope = push_scope (class_type);
}
/* Make sure that any template parameters are in scope. */
@@ -27770,9 +27776,12 @@ cp_parser_class_specifier (cp_parser* pa
tree ctx = DECL_CONTEXT (decl);
if (class_type != ctx)
{
+ if (class_type && TYPE_FIELDS (class_type) != class_type_fields)
+ fixup_type_variants (class_type);
if (pushed_scope)
pop_scope (pushed_scope);
class_type = ctx;
+ class_type_fields = TYPE_FIELDS (class_type);
pushed_scope = push_scope (class_type);
}
@@ -27832,9 +27841,12 @@ cp_parser_class_specifier (cp_parser* pa
tree ctx = type_context_for_name_lookup (decl);
if (class_type != ctx)
{
+ if (class_type && TYPE_FIELDS (class_type) != class_type_fields)
+ fixup_type_variants (class_type);
if (pushed_scope)
pop_scope (pushed_scope);
class_type = ctx;
+ class_type_fields = TYPE_FIELDS (class_type);
pushed_scope = push_scope (class_type);
}
inject_this_parameter (class_type, TYPE_UNQUALIFIED);
@@ -27848,9 +27860,12 @@ cp_parser_class_specifier (cp_parser* pa
tree ctx = DECL_CONTEXT (decl);
if (class_type != ctx)
{
+ if (class_type && TYPE_FIELDS (class_type) != class_type_fields)
+ fixup_type_variants (class_type);
if (pushed_scope)
pop_scope (pushed_scope);
class_type = ctx;
+ class_type_fields = TYPE_FIELDS (class_type);
pushed_scope = push_scope (class_type);
}
@@ -27891,6 +27906,9 @@ cp_parser_class_specifier (cp_parser* pa
}
vec_safe_truncate (unparsed_contracts, 0);
+ if (class_type && TYPE_FIELDS (class_type) != class_type_fields)
+ fixup_type_variants (class_type);
+
current_class_ptr = NULL_TREE;
current_class_ref = NULL_TREE;
if (pushed_scope)