https://gcc.gnu.org/g:d4077ce639a2e5f8a12e531aa84fcf631aa5ba34
commit r16-4307-gd4077ce639a2e5f8a12e531aa84fcf631aa5ba34 Author: Martin Uecker <[email protected]> Date: Sat Aug 30 19:05:05 2025 +0200 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. Diff: --- gcc/c/c-parser.cc | 6 +++--- gcc/testsuite/gcc.dg/c11-generic-2.c | 2 +- gcc/testsuite/gcc.dg/c2y-generic-3.c | 4 ++-- gcc/testsuite/gcc.dg/c2y-generic-4.c | 10 ++++++++++ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index 7c2452644bde..bc90be47151b 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -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 %<:%>")) diff --git a/gcc/testsuite/gcc.dg/c11-generic-2.c b/gcc/testsuite/gcc.dg/c11-generic-2.c index 90be650af280..a74838025386 100644 --- a/gcc/testsuite/gcc.dg/c11-generic-2.c +++ b/gcc/testsuite/gcc.dg/c11-generic-2.c @@ -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" } */ diff --git a/gcc/testsuite/gcc.dg/c2y-generic-3.c b/gcc/testsuite/gcc.dg/c2y-generic-3.c index 09174fdb095d..f3a807e06b49 100644 --- a/gcc/testsuite/gcc.dg/c2y-generic-3.c +++ b/gcc/testsuite/gcc.dg/c2y-generic-3.c @@ -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); } diff --git a/gcc/testsuite/gcc.dg/c2y-generic-4.c b/gcc/testsuite/gcc.dg/c2y-generic-4.c new file mode 100644 index 000000000000..8172ed45e741 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2y-generic-4.c @@ -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" } */ +} +
