Bootstrapped and regression tested on x86_64.

    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:
            gcc/c/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 --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index df44a915ed4..c773baaf62f 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 90be650af28..a7483802538 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 09174fdb095..f3a807e06b4 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 00000000000..8172ed45e74
--- /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" } */
+}
+

Reply via email to