From: Joseph Myers Date: Wed, 28 Oct 2020 18:57:02 +0000 (+0000) Subject: c: Allow omitted parameter names for C2x X-Git-Tag: upstream/12.2.0~12460 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a4223abb3deb24e8104bbfec6f0f21579c1889e3;p=platform%2Fupstream%2Fgcc.git c: Allow omitted parameter names for C2x C2x allows parameter names to be omitted in function definitions, as in C++; add support for this feature. As with other features that only result in previously rejected code being accepted, this feature is now accepted as an extension for previous standard versions, with a pedwarn-if-pedantic that is disabled by -Wno-c11-c2x-compat. The logic for avoiding unused-parameter warnings for unnamed parameters is in code shared between C and C++, so no changes are needed there. Bootstrapped with no regressions for x86_64-pc-linux-gnu. gcc/c/ 2020-10-28 Joseph Myers * c-decl.c (store_parm_decls_newstyle): Use pedwarn_c11 not error_at for omitted parameter name. gcc/testsuite/ 2020-10-28 Joseph Myers * gcc.dg/c11-parm-omit-1.c, gcc.dg/c11-parm-omit-2.c, gcc.dg/c11-parm-omit-3.c, gcc.dg/c11-parm-omit-4.c, gcc.dg/c2x-parm-omit-1.c, gcc.dg/c2x-parm-omit-2.c, gcc.dg/c2x-parm-omit-3.c, gcc.dg/c2x-parm-omit-4.c: New tests. * gcc.dg/noncompile/pr79758.c: Do not expect error for omitted parameter name. --- diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 1673b95..a5d0b15 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -9630,7 +9630,9 @@ store_parm_decls_newstyle (tree fndecl, const struct c_arg_info *arg_info) warn_if_shadowing (decl); } else - error_at (DECL_SOURCE_LOCATION (decl), "parameter name omitted"); + pedwarn_c11 (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic, + "ISO C does not support omitting parameter names in " + "function definitions before C2X"); } /* Record the parameter list in the function declaration. */ diff --git a/gcc/testsuite/gcc.dg/c11-parm-omit-1.c b/gcc/testsuite/gcc.dg/c11-parm-omit-1.c new file mode 100644 index 0000000..83d1b50 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c11-parm-omit-1.c @@ -0,0 +1,5 @@ +/* Test omitted parameter names not in C11: -pedantic-errors. */ +/* { dg-do compile } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +void f (int) { } /* { dg-error "omitting parameter names" } */ diff --git a/gcc/testsuite/gcc.dg/c11-parm-omit-2.c b/gcc/testsuite/gcc.dg/c11-parm-omit-2.c new file mode 100644 index 0000000..2efd450 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c11-parm-omit-2.c @@ -0,0 +1,5 @@ +/* Test omitted parameter names not in C11: -pedantic. */ +/* { dg-do compile } */ +/* { dg-options "-std=c11 -pedantic" } */ + +void f (int) { } /* { dg-warning "omitting parameter names" } */ diff --git a/gcc/testsuite/gcc.dg/c11-parm-omit-3.c b/gcc/testsuite/gcc.dg/c11-parm-omit-3.c new file mode 100644 index 0000000..5bf27a0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c11-parm-omit-3.c @@ -0,0 +1,5 @@ +/* Test omitted parameter names not in C11: -pedantic -Wno-c11-c2x-compat. */ +/* { dg-do compile } */ +/* { dg-options "-std=c11 -pedantic -Wno-c11-c2x-compat" } */ + +void f (int) { } diff --git a/gcc/testsuite/gcc.dg/c11-parm-omit-4.c b/gcc/testsuite/gcc.dg/c11-parm-omit-4.c new file mode 100644 index 0000000..ea4cbfa --- /dev/null +++ b/gcc/testsuite/gcc.dg/c11-parm-omit-4.c @@ -0,0 +1,6 @@ +/* Test omitted parameter names not in C11: accepted by default in the + absence of -pedantic. */ +/* { dg-do compile } */ +/* { dg-options "-std=c11" } */ + +void f (int) { } diff --git a/gcc/testsuite/gcc.dg/c2x-parm-omit-1.c b/gcc/testsuite/gcc.dg/c2x-parm-omit-1.c new file mode 100644 index 0000000..0dc89bb --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-parm-omit-1.c @@ -0,0 +1,5 @@ +/* Test omitted parameter names in C2x. */ +/* { dg-do compile } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ + +void f (int) { } diff --git a/gcc/testsuite/gcc.dg/c2x-parm-omit-2.c b/gcc/testsuite/gcc.dg/c2x-parm-omit-2.c new file mode 100644 index 0000000..7d68933 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-parm-omit-2.c @@ -0,0 +1,10 @@ +/* Test omitted parameter names in C2x. Warning test: there should be + no warning for an unnamed parameter being unused. */ +/* { dg-do compile } */ +/* { dg-options "-std=c2x -pedantic-errors -Wall -Wextra" } */ + +int +f (int a, int, int c, int d) /* { dg-warning "unused parameter 'd'" } */ +{ + return a + c; +} diff --git a/gcc/testsuite/gcc.dg/c2x-parm-omit-3.c b/gcc/testsuite/gcc.dg/c2x-parm-omit-3.c new file mode 100644 index 0000000..dac258b --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-parm-omit-3.c @@ -0,0 +1,23 @@ +/* Test omitted parameter names in C2x. Execution test. */ +/* { dg-do run } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ + +extern void abort (void); +extern void exit (int); + +void +f (int a, int [++a], int b) +{ + /* Verify array size expression of unnamed parameter is processed as + expected. */ + if (a != 2 || b != 3) + abort (); +} + +int +main (void) +{ + int t[2]; + f (1, t, 3); + exit (0); +} diff --git a/gcc/testsuite/gcc.dg/c2x-parm-omit-4.c b/gcc/testsuite/gcc.dg/c2x-parm-omit-4.c new file mode 100644 index 0000000..a4b0deb --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-parm-omit-4.c @@ -0,0 +1,5 @@ +/* Test omitted parameter names in C2x: diagnosed with -Wc11-c2x-compat. */ +/* { dg-do compile } */ +/* { dg-options "-std=c2x -pedantic-errors -Wc11-c2x-compat" } */ + +void f (int) { } /* { dg-warning "omitting parameter names" } */ diff --git a/gcc/testsuite/gcc.dg/noncompile/pr79758.c b/gcc/testsuite/gcc.dg/noncompile/pr79758.c index aeaf7c7..a312160 100644 --- a/gcc/testsuite/gcc.dg/noncompile/pr79758.c +++ b/gcc/testsuite/gcc.dg/noncompile/pr79758.c @@ -1,6 +1,6 @@ /* PR c/79758 */ /* { dg-do compile } */ -void fn1 (int[a]) { }; /* { dg-error "undeclared here|parameter name omitted" } */ +void fn1 (int[a]) { }; /* { dg-error "undeclared here" } */ void fn1 (b) { }; /* { dg-error "redefinition" } */ /* { dg-warning "defaults to 'int'" "" { target *-*-* } .-1 } */