Skip to content
Snippets Groups Projects
Commit ad2908ed authored by Jakub Jelinek's avatar Jakub Jelinek Committed by Jakub Jelinek
Browse files

c: Assorted fixes for flexible array members in unions [PR119001]

r15-209 allowed flexible array members inside of unions, but as the
following testcase shows, not everything has been adjusted for that.
Unlike structures, in unions flexible array member (as an extension)
can be any of the members, not just the last one, as in union all
members are effectively last.
The first hunk is about an ICE on the initialization of the FAM
in union which is not the last FIELD_DECL with a string literal,
the second hunk just formatting fix, third hunk fixes a bug in which
we were just throwing away the initializers (except for with string literal)
of FAMs in unions which aren't the last FIELD_DECL, and the last hunk
is to diagnose FAM errors in unions the same as for structures, in
particular trying to initialize a FAM with non-constant or initialization
in nested context.

2025-02-26  Jakub Jelinek  <jakub@redhat.com>

	PR c/119001
gcc/
	* varasm.cc (output_constructor_regular_field): Don't fail
	assertion if next is non-NULL and FIELD_DECL if
	TREE_CODE (local->type) is UNION_TYPE.
gcc/c/
	* c-typeck.cc (pop_init_level): Don't clear constructor_type
	if DECL_CHAIN of constructor_fields is NULL but p->type is UNION_TYPE.
	Formatting fix.
	(process_init_element): Diagnose non-static initialization of flexible
	array member in union or FAM in union initialization in nested context.
gcc/testsuite/
	* gcc.dg/pr119001-1.c: New test.
	* gcc.dg/pr119001-2.c: New test.
parent 8d22474a
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment