mirror of git://gcc.gnu.org/git/gcc.git
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:
parent
3f70e62553
commit
d4077ce639
|
@ -11253,9 +11253,9 @@ c_parser_generic_selection (c_parser *parser)
|
||||||
"incomplete type before C2Y");
|
"incomplete type before C2Y");
|
||||||
|
|
||||||
if (c_type_variably_modified_p (assoc.type))
|
if (c_type_variably_modified_p (assoc.type))
|
||||||
error_at (assoc.type_location,
|
pedwarn_c23 (assoc.type_location, OPT_Wpedantic,
|
||||||
"%<_Generic%> association has "
|
"ISO C does not support %<_Generic%> association with "
|
||||||
"variable length type");
|
"variably-modified type before C2Y");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
|
if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
|
||||||
|
|
|
@ -11,7 +11,7 @@ f (int n)
|
||||||
_Generic (n, default: 1, default: 2); /* { dg-error "duplicate .*default.* case" } */
|
_Generic (n, default: 1, default: 2); /* { dg-error "duplicate .*default.* case" } */
|
||||||
|
|
||||||
/* Variably-modified type not ok. */
|
/* 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. */
|
/* Type must be complete. */
|
||||||
_Generic (n, struct incomplete: 0, default: 1); /* { dg-error "incomplete type" } */
|
_Generic (n, struct incomplete: 0, default: 1); /* { dg-error "incomplete type" } */
|
||||||
_Generic (n, void: 0, default: 1); /* { dg-error "incomplete type" } */
|
_Generic (n, void: 0, default: 1); /* { dg-error "incomplete type" } */
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
/* Test C2Y _Generic features: VM types still not allowed. */
|
/* Test C2Y _Generic features: VM types allowed. */
|
||||||
/* { dg-do compile } */
|
/* { dg-do compile } */
|
||||||
/* { dg-options "-std=c2y -pedantic-errors" } */
|
/* { dg-options "-std=c2y -pedantic-errors" } */
|
||||||
|
|
||||||
void
|
void
|
||||||
f (int i)
|
f (int i)
|
||||||
{
|
{
|
||||||
(void) _Generic (i, int : 1, int (*)[i] : 2); /* { dg-error "variable length" } */
|
(void) _Generic (i, int : 1, int (*)[i] : 2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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" } */
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue