From patchwork Wed Oct 28 18:59:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 1389383 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CLyYB71Rkz9sW0 for ; Thu, 29 Oct 2020 05:59:25 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E0F01397303A; Wed, 28 Oct 2020 18:59:22 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa1.mentor.iphmx.com (esa1.mentor.iphmx.com [68.232.129.153]) by sourceware.org (Postfix) with ESMTPS id A314B3857C60 for ; Wed, 28 Oct 2020 18:59:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A314B3857C60 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=joseph_myers@mentor.com IronPort-SDR: stMqRVxW8s/ti4XX1hFWRj+tjitTNPxTrA5iweHqBycrC3OHDdIpUyHT3eRWzrIIkyh+AmGufO lNWJgj09J1DfL8skE1EYS1zNfE7U3SiOYI35ZJyrKGezQKB4SokTaHPoQfm0GTnZEZGSdQewDW W9PNki761ITWzljbwHY/AfWfL/rpE/B16pCZQiQUZDbqpnW6/tp0QCSQy9ieiWAOJdvYB5d4Np W+h3cI3dcRLqMk2/gGhzhM6q9Rq+EaTXQMACM0L0sT0gpbX9G3boJmpFWNcrL1K1d5YIATYyGZ KIc= X-IronPort-AV: E=Sophos;i="5.77,427,1596528000"; d="scan'208";a="56732339" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 28 Oct 2020 10:59:18 -0800 IronPort-SDR: Dt5EZQmskdBVRwViF867O2Y5ig7noRzEIP/gskK7hNJMcOv/UBsjTax8flVIW7L8aSCgfP6br3 97Mg4hNH6unpucC5DzweIpzA5So6mA+EU9d1bg1uRo+PzqHTmX79tdS5IedCtXCh0JPV7+wShO vO9kZrTsSD2eUMi3zayITL1MF4Zoot3Anl1kMv0jzLUryJtunTMuFhB2mtCfk5XW3SelhzU2rC xytnJkBQkeCSAX9lFmEIzVdkWB5b+K+BPbqL3gIZbsvCb51GYSRwTXGEFPnP02WwvJ6GX6L6BO Z8E= Date: Wed, 28 Oct 2020 18:59:13 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: Subject: c: Allow omitted parameter names for C2x Message-ID: User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-3131.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" 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. Applied to mainline. 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 1673b958555..a5d0b158a26 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 00000000000..83d1b508286 --- /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 00000000000..2efd4505db3 --- /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 00000000000..5bf27a03aff --- /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 00000000000..ea4cbfa9928 --- /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 00000000000..0dc89bb0270 --- /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 00000000000..7d689332813 --- /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 00000000000..dac258b0fb8 --- /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 00000000000..a4b0deb7abc --- /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 aeaf7c71dec..a31216068f0 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 } */