Diagnose use of [*] in old-style parameter definitions (PR c/88704)

Message ID alpine.DEB.2.21.1912030127470.23075@digraph.polyomino.org.uk
State New
Headers show
Series
  • Diagnose use of [*] in old-style parameter definitions (PR c/88704)
Related show

Commit Message

Joseph Myers Dec. 3, 2019, 1:28 a.m.
GCC wrongly accepts [*] in old-style parameter definitions because
because parm_flag is set on the scope used for those definitions and,
unlike the case of a prototype in a function definition, there is no
subsequent check to disallow this invalid usage.  This patch adds such
a check.  (At this point we don't have location information for the
[*], so the diagnostic location isn't ideal.)

Bootstrapped with no regressions for x86_64-pc-linux-gnu.  Applied to 
mainline.

gcc/c:
2019-12-03  Joseph Myers  <joseph@codesourcery.com>

	PR c/88704
	* c-decl.c (store_parm_decls_oldstyle): Diagnose use of [*] in
	old-style parameter definitions.

gcc/testsuite:
2019-12-03  Joseph Myers  <joseph@codesourcery.com>

	PR c/88704
	* gcc.dg/vla-25.c: New test.


-- 
Joseph S. Myers
joseph@codesourcery.com

Patch

Index: gcc/c/c-decl.c
===================================================================
--- gcc/c/c-decl.c	(revision 278912)
+++ gcc/c/c-decl.c	(working copy)
@@ -9394,6 +9394,9 @@  store_parm_decls_oldstyle (tree fndecl, const stru
 		    "old-style function definition");
     }
 
+  if (current_scope->had_vla_unspec)
+    error ("%<[*]%> not allowed in other than function prototype scope");
+
   /* Match each formal parameter name with its declaration.  Save each
      decl in the appropriate TREE_PURPOSE slot of the parmids chain.  */
   for (parm = parmids; parm; parm = TREE_CHAIN (parm))
Index: gcc/testsuite/gcc.dg/vla-25.c
===================================================================
--- gcc/testsuite/gcc.dg/vla-25.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/vla-25.c	(working copy)
@@ -0,0 +1,9 @@ 
+/* Test [*] diagnosed on old-style parameter declaration.  PR c/88704.  */
+/* { dg-do compile } */
+/* { dg-options "-std=c99 -pedantic-errors" } */
+
+void
+f (x)
+     int x[*];
+{ /* { dg-error "not allowed in other than function prototype scope" } */
+}