c: Allow variably-modified types in generic associations for C2Y

This implements part of N3348 to allow variably-modified types in
generic associations in C2Y and making it a pedantic warning before.
Allowing star * is not yet implemented.

gcc/c/ChangeLog:
	* c-parser.cc (c_parser_generic_selection): Change
	error_at to pedwarn_c23.

gcc/testsuite/ChangeLog:
	* gcc.dg/c11-generic-2.c: Adapt error message.
	* gcc.dg/c2y-generic-3.c: Adapt test.
	* gcc.dg/c2y-generic-4.c: New test.
This commit is contained in:
Martin Uecker 2025-08-30 19:05:05 +02:00 committed by Martin Uecker
parent 3f70e62553
commit d4077ce639
4 changed files with 16 additions and 6 deletions

View File

@ -11253,9 +11253,9 @@ c_parser_generic_selection (c_parser *parser)
"incomplete type before C2Y");
if (c_type_variably_modified_p (assoc.type))
error_at (assoc.type_location,
"%<_Generic%> association has "
"variable length type");
pedwarn_c23 (assoc.type_location, OPT_Wpedantic,
"ISO C does not support %<_Generic%> association with "
"variably-modified type before C2Y");
}
if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))

View File

@ -11,7 +11,7 @@ f (int n)
_Generic (n, default: 1, default: 2); /* { dg-error "duplicate .*default.* case" } */
/* Variably-modified type not ok. */
_Generic (n, int[n]: 0, default: 1); /* { dg-error "variable length type" } */
_Generic (n, int[n]: 0, default: 1); /* { dg-error "variably-modified" } */
/* Type must be complete. */
_Generic (n, struct incomplete: 0, default: 1); /* { dg-error "incomplete type" } */
_Generic (n, void: 0, default: 1); /* { dg-error "incomplete type" } */

View File

@ -1,9 +1,9 @@
/* Test C2Y _Generic features: VM types still not allowed. */
/* Test C2Y _Generic features: VM types allowed. */
/* { dg-do compile } */
/* { dg-options "-std=c2y -pedantic-errors" } */
void
f (int i)
{
(void) _Generic (i, int : 1, int (*)[i] : 2); /* { dg-error "variable length" } */
(void) _Generic (i, int : 1, int (*)[i] : 2);
}

View File

@ -0,0 +1,10 @@
/* Test C2Y _Generic features: VM types allowed. Warn for -Wc23-c2y-compat */
/* { dg-do compile } */
/* { dg-options "-std=c2y -pedantic-errors -Wc23-c2y-compat" } */
void
f (int i)
{
(void) _Generic (i, int : 1, int (*)[i] : 2); /* { dg-warning "variably-modified type" } */
}