From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 57205388266C for ; Mon, 20 Nov 2023 09:56:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 57205388266C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 57205388266C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700474209; cv=none; b=bcMavQkhbVOa2G2qF79SaFSEBS2IqhmfcMg2aDGb/HI7wigDYme4wBiZyZersQ90rWnw9qIR5JwBHWyWoclIsmmTrMjKh2wKJPTPhFtBj1ykLv56/uc7inG+zzwfb0PKqXspS1Sm/5/MhyIP/V7i29vofDQVK/fikGxaptGyF4Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700474209; c=relaxed/simple; bh=RYzwj2kJggj9eYo9Aswm1wZ1ERqypomiq/EfiOB24xg=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=GNnFeFWIUtSMrp7SCMyJCql258Oor2F1vthj3KtNCodoJtIkj/Yeztahslie0xm4CziMvSO76so0yrwVdXv6y8PFfGvHB1qmOMrECTXMQDHfqpUTHTALFhpyEga69FyeA3ZUx0DNk4f/QoiU+WtdlKs2SdLjHbvgN8EYxa9XxxA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700474206; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=B9Xtw36foXpldHnpj+O0uDIQCVuLID97f7xr/BLEFDI=; b=bd+VmldIuwkH3lvbVpNZFkvL9M+a6eBmnvZY0GdHAdEBDrD8xkGHRGDtxkS2SsVRanDyPp HDzBrGgXzQs4g6lGSUEFzPLXSC2b/ybIDmC6Tiz1WOqX1wAeIT0VodBR35yAXJPRpX2KC4 /ToK61wWoIKW7tgvR1uvTz/eREDgtis= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-495-JSaDcjduMSSCDAGGnOqu0Q-1; Mon, 20 Nov 2023 04:56:45 -0500 X-MC-Unique: JSaDcjduMSSCDAGGnOqu0Q-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 10A15185A780 for ; Mon, 20 Nov 2023 09:56:45 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 38ED9492BE0 for ; Mon, 20 Nov 2023 09:56:44 +0000 (UTC) From: Florian Weimer To: gcc-patches@gcc.gnu.org Subject: [PATCH v3 11/11] c: Add new -Wdeclaration-missing-parameter-type permerror In-Reply-To: Message-ID: <700d70e4a2874645ddb67a8a335131d83b242e69.1700473918.git.fweimer@redhat.com> References: X-From-Line: 700d70e4a2874645ddb67a8a335131d83b242e69 Mon Sep 17 00:00:00 2001 Date: Mon, 20 Nov 2023 10:56:42 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.3 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This used to be a warning, enabled by default, without its own option. A subsequent change could improve diagnostics and provide spelling hints for declarations like =E2=80=9Cvoid function (int32t);=E2=80=9D. gcc/c-family/ =09* c.opt (Wdeclaration-missing-parameter-type): New. gcc/c/ChangeLog: =09PR other/44209 =09* c-decl.cc (grokparms): Issue permerror for =09OPT_Wdeclaration_missing_parameter_type instead of a pedwarn. gcc/ChangeLog: =09* doc/invoke.texi (Warning Options): Document =09-Wdeclaration-missing-parameter-type. gcc/testsuite/ChangeLog: =09* gcc.dg/permerror-default.c (missing_parameter_type): =09Expect error. =09* gcc.dg/permerror-fpermissive.c (missing_parameter_type): =09Expect -Wdeclaration-missing-parameter-type warning. =09* gcc.dg/permerror-gnu89-nopermissive.c (missing_parameter_type): =09Expect -Wdeclaration-missing-parameter-type error. =09* gcc.dg/permerror-gnu89-pedantic.c (missing_parameter_type): =09Likewise. =09* gcc.dg/permerror-gnu89.c (missing_parameter_type): =09Expect -Wdeclaration-missing-parameter-type warning. =09* gcc.dg/permerror-noerror.c: Add =09-Wno-error=3Ddeclaration-missing-parameter-type to build flags. =09(missing_parameter_type): Expect =09-Wdeclaration-missing-parameter-type warning. =09* gcc.dg/permerror-nowarning.c: Build with =09-Wno-declaration-missing-parameter-type. Remove previously =09expected warning. =09* gcc.dg/permerror-fpermissive-nowarning.c: Likewise. =09* gcc.dg/permerror-pedantic.c (missing_parameter_type): =09Expect -Wdeclaration-missing-parameter-type error. =09* gcc.dg/permerror-system.c (missing_parameter_type): =09Likewise. --- gcc/c-family/c.opt | 4 ++++ gcc/c/c-decl.cc | 6 ++++-- gcc/doc/invoke.texi | 17 ++++++++++++++++- gcc/testsuite/gcc.dg/permerror-default.c | 2 +- .../gcc.dg/permerror-fpermissive-nowarning.c | 7 +------ gcc/testsuite/gcc.dg/permerror-fpermissive.c | 2 +- .../gcc.dg/permerror-gnu89-nopermissive.c | 2 +- gcc/testsuite/gcc.dg/permerror-gnu89-pedantic.c | 2 +- gcc/testsuite/gcc.dg/permerror-gnu89.c | 2 +- gcc/testsuite/gcc.dg/permerror-noerror.c | 4 ++-- gcc/testsuite/gcc.dg/permerror-nowarning.c | 7 +------ gcc/testsuite/gcc.dg/permerror-pedantic.c | 2 +- gcc/testsuite/gcc.dg/permerror-system.c | 2 ++ 13 files changed, 36 insertions(+), 23 deletions(-) diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index b10c6057cd1..723e8c3e27b 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -591,6 +591,10 @@ Wdeclaration-after-statement C ObjC Var(warn_declaration_after_statement) Init(-1) Warning Warn when a declaration is found after a statement. =20 +Wdeclaration-missing-parameter-type +C ObjC Var(warn_declaration_missing_parameter) Warning Init(1) +Warn for missing parameter types in function declarations. + Wdelete-incomplete C++ ObjC++ Var(warn_delete_incomplete) Init(1) Warning Warn when deleting a pointer to incomplete type. diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index d16958113a8..3d9bee54259 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -8337,8 +8337,10 @@ grokparms (struct c_arg_info *arg_info, bool funcdef= _flag) { if (!funcdef_flag) =09{ -=09 pedwarn (input_location, 0, "parameter names (without types) in " -=09=09 "function declaration"); +=09 permerror_opt (input_location, +=09=09=09 OPT_Wdeclaration_missing_parameter_type, +=09=09=09 "parameter names (without types) in " +=09=09=09 "function declaration"); =09 arg_info->parms =3D NULL_TREE; =09} else diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index be33da71c44..7f5da45dcea 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -504,7 +504,8 @@ Objective-C and Objective-C++ Dialects}. =20 @item C and Objective-C-only Warning Options @gccoptlist{-Wbad-function-cast -Wmissing-declarations --Wmissing-parameter-type -Wmissing-prototypes -Wmissing-variable-declarati= ons +-Wmissing-parameter-type -Wdeclaration-missing-parameter-type +-Wmissing-prototypes -Wmissing-variable-declarations -Wnested-externs -Wold-style-declaration -Wold-style-definition -Wstrict-prototypes -Wtraditional -Wtraditional-conversion -Wdeclaration-after-statement -Wpointer-sign} @@ -9734,6 +9735,20 @@ void foo(bar) @{ @} =20 This warning is also enabled by @option{-Wextra}. =20 +@opindex Wno-declaration-missing-parameter-type +@opindex Wdeclaration-missing-parameter-type +@item -Wno-declaration-missing-parameter-type @r{(C and Objective-C only)} +Do not warn if a function declaration contains a parameter name without +a type. Such function declarations do not provide a function prototype +and prevent most type checking in function calls. + +This warning is enabled by default. In C99 and later dialects of C, it +is treated as an error. The error can be downgraded to a warning using +@option{-fpermissive} (along with certain other errors), or for this +error alone, with @option{-Wno-error=3Ddeclaration-missing-parameter-type}= . + +This warning is upgraded to an error by @option{-pedantic-errors}. + @opindex Wmissing-prototypes @opindex Wno-missing-prototypes @item -Wmissing-prototypes @r{(C and Objective-C only)} diff --git a/gcc/testsuite/gcc.dg/permerror-default.c b/gcc/testsuite/gcc.d= g/permerror-default.c index 45b58b0131d..c674d689081 100644 --- a/gcc/testsuite/gcc.dg/permerror-default.c +++ b/gcc/testsuite/gcc.dg/permerror-default.c @@ -19,7 +19,7 @@ implicit_int_4 (i) /* { dg-error "return type defaults to= 'int' \\\[-Wimplicit-i (const) 0; /* { dg-error "type defaults to 'int' in type name \\\[-Wimpl= icit-int\\\]" } */ } =20 -extern int missing_parameter_type (i); /* { dg-warning "parameter names \\= \(without types\\\) in function declaration\n" } */ +extern int missing_parameter_type (i); /* { dg-error "parameter names \\\(= without types\\\) in function declaration \\\[-Wdeclaration-missing-paramet= er-type\\\]" } */ =20 =20 int * diff --git a/gcc/testsuite/gcc.dg/permerror-fpermissive-nowarning.c b/gcc/t= estsuite/gcc.dg/permerror-fpermissive-nowarning.c index f15b21ef43d..d07c8636677 100644 --- a/gcc/testsuite/gcc.dg/permerror-fpermissive-nowarning.c +++ b/gcc/testsuite/gcc.dg/permerror-fpermissive-nowarning.c @@ -1,11 +1,6 @@ -/* { dg-options "-fpermissive -Wno-implicit-function-declaration -Wno-impl= icit-int -Wno-int-conversion -Wno-incompatible-pointer-types -Wno-return-mi= smatch" } */ +/* { dg-options "-fpermissive -Wno-implicit-function-declaration -Wno-impl= icit-int -Wno-int-conversion -Wno-incompatible-pointer-types -Wno-return-mi= smatch -Wno-declaration-missing-parameter-type" } */ =20 /* This test checks that permerrors can be disabled using -Wno-* options e= ven if -fpermissive is used. */ =20 #include "permerror-default.c" - -/* Ideally, we do not want to see any warnings here, but this warning is n= ot - yet controlled by its own option. */ - -/* { dg-warning "parameter names \\\(without types\\\) in function declara= tion\n" "" { target *-*-* } 22 } */ diff --git a/gcc/testsuite/gcc.dg/permerror-fpermissive.c b/gcc/testsuite/g= cc.dg/permerror-fpermissive.c index 139f35ad1c0..fd3020d75ee 100644 --- a/gcc/testsuite/gcc.dg/permerror-fpermissive.c +++ b/gcc/testsuite/gcc.dg/permerror-fpermissive.c @@ -19,7 +19,7 @@ implicit_int_4 (i) /* { dg-warning "return type defaults = to 'int' \\\[-Wimplicit (const) 0; /* { dg-warning "type defaults to 'int' in type name \\\[-Wim= plicit-int\\\]" } */ } =20 -extern int missing_parameter_type (i); /* { dg-warning "parameter names \\= \(without types\\\) in function declaration\n" } */ +extern int missing_parameter_type (i); /* { dg-warning "parameter names \\= \(without types\\\) in function declaration \\\[-Wdeclaration-missing-param= eter-type\\\]" } */ =20 =20 int * diff --git a/gcc/testsuite/gcc.dg/permerror-gnu89-nopermissive.c b/gcc/test= suite/gcc.dg/permerror-gnu89-nopermissive.c index 93504b94139..aba4b2498f7 100644 --- a/gcc/testsuite/gcc.dg/permerror-gnu89-nopermissive.c +++ b/gcc/testsuite/gcc.dg/permerror-gnu89-nopermissive.c @@ -19,7 +19,7 @@ implicit_int_4 (i) /* { dg-bogus "-Wimplicit-int" } */ (const) 0; /* { dg-bogus "-Wimplicit-int" } */ } =20 -extern int missing_parameter_type (i); /* { dg-warning "parameter names \\= \(without types\\\) in function declaration\n" } */ +extern int missing_parameter_type (i); /* { dg-error "parameter names \\\(= without types\\\) in function declaration \\\[-Wdeclaration-missing-paramet= er-type\\\]" } */ =20 =20 int * diff --git a/gcc/testsuite/gcc.dg/permerror-gnu89-pedantic.c b/gcc/testsuit= e/gcc.dg/permerror-gnu89-pedantic.c index 465a16f5f9a..ef4dbfc86c5 100644 --- a/gcc/testsuite/gcc.dg/permerror-gnu89-pedantic.c +++ b/gcc/testsuite/gcc.dg/permerror-gnu89-pedantic.c @@ -19,7 +19,7 @@ implicit_int_4 (i) /* { dg-bogus "-Wimplicit-int" } */ (const) 0; /* { dg-bogus "-Wimplicit-int" } */ } =20 -extern int missing_parameter_type (i); /* { dg-error "parameter names \\\(= without types\\\) in function declaration\n" } */ +extern int missing_parameter_type (i); /* { dg-error "parameter names \\\(= without types\\\) in function declaration \\\[-Wdeclaration-missing-paramet= er-type\\\]" } */ =20 =20 int * diff --git a/gcc/testsuite/gcc.dg/permerror-gnu89.c b/gcc/testsuite/gcc.dg/= permerror-gnu89.c index 66f7789269f..83792ecfaac 100644 --- a/gcc/testsuite/gcc.dg/permerror-gnu89.c +++ b/gcc/testsuite/gcc.dg/permerror-gnu89.c @@ -19,7 +19,7 @@ implicit_int_4 (i) /* { dg-bogus "-Wimplicit-int" } */ (const) 0; /* { dg-bogus "-Wimplicit-int" } */ } =20 -extern int missing_parameter_type (i); /* { dg-warning "parameter names \\= \(without types\\\) in function declaration\n" } */ +extern int missing_parameter_type (i); /* { dg-warning "parameter names \\= \(without types\\\) in function declaration \\\[-Wdeclaration-missing-param= eter-type\\\]" } */ =20 =20 int * diff --git a/gcc/testsuite/gcc.dg/permerror-noerror.c b/gcc/testsuite/gcc.d= g/permerror-noerror.c index cd1c2013cb5..fc68dfa8bb9 100644 --- a/gcc/testsuite/gcc.dg/permerror-noerror.c +++ b/gcc/testsuite/gcc.dg/permerror-noerror.c @@ -1,4 +1,4 @@ -/* { dg-options "-Wno-error=3Dimplicit-function-declaration -Wno-error=3Di= mplicit-int -Wno-error=3Dint-conversion -Wno-error=3Dincompatible-pointer-t= ypes -Wno-error=3Dreturn-mismatch" } */ +/* { dg-options "-Wno-error=3Dimplicit-function-declaration -Wno-error=3Di= mplicit-int -Wno-error=3Dint-conversion -Wno-error=3Dincompatible-pointer-t= ypes -Wno-error=3Dreturn-mismatch -Wno-error=3Ddeclaration-missing-paramete= r-type" } */ =20 /* This test should emulate the effect of -fpermissive by adding all the -Wno-error=3D options that are implied by -fpermissive. It needs to be @@ -19,7 +19,7 @@ implicit_int_4 (i) /* { dg-warning "return type defaults = to 'int' \\\[-Wimplicit (const) 0; /* { dg-warning "type defaults to 'int' in type name \\\[-Wim= plicit-int\\\]" } */ } =20 -extern int missing_parameter_type (i); /* { dg-warning "parameter names \\= \(without types\\\) in function declaration\n" } */ +extern int missing_parameter_type (i); /* { dg-warning "parameter names \\= \(without types\\\) in function declaration \\\[-Wdeclaration-missing-param= eter-type\\\]" } */ =20 =20 int * diff --git a/gcc/testsuite/gcc.dg/permerror-nowarning.c b/gcc/testsuite/gcc= .dg/permerror-nowarning.c index da6bd08245d..b1cf7990127 100644 --- a/gcc/testsuite/gcc.dg/permerror-nowarning.c +++ b/gcc/testsuite/gcc.dg/permerror-nowarning.c @@ -1,10 +1,5 @@ -/* { dg-options "-Wno-implicit-function-declaration -Wno-implicit-int -Wno= -int-conversion -Wno-incompatible-pointer-types -Wno-return-mismatch" } */ +/* { dg-options "-Wno-implicit-function-declaration -Wno-implicit-int -Wno= -int-conversion -Wno-incompatible-pointer-types -Wno-return-mismatch -Wno-d= eclaration-missing-parameter-type" } */ =20 /* This test checks that permerrors can be disabled using -Wno-* options. = */ =20 #include "permerror-default.c" - -/* Ideally, we do not want to see any warnings here, but this warning is n= ot - yet controlled by its own option. */ - -/* { dg-warning "parameter names \\\(without types\\\) in function declara= tion\n" "" { target *-*-* } 22 } */ diff --git a/gcc/testsuite/gcc.dg/permerror-pedantic.c b/gcc/testsuite/gcc.= dg/permerror-pedantic.c index 95dda18acd4..2380bb2583c 100644 --- a/gcc/testsuite/gcc.dg/permerror-pedantic.c +++ b/gcc/testsuite/gcc.dg/permerror-pedantic.c @@ -19,7 +19,7 @@ implicit_int_4 (i) /* { dg-error "return type defaults to= 'int' \\\[-Wimplicit-i (const) 0; /* { dg-error "type defaults to 'int' in type name \\\[-Wimpl= icit-int\\\]" } */ } =20 -extern int missing_parameter_type (i); /* { dg-error "parameter names \\\(= without types\\\) in function declaration\n" } */ +extern int missing_parameter_type (i); /* { dg-error "parameter names \\\(= without types\\\) in function declaration \\\[-Wdeclaration-missing-paramet= er-type\\\]" } */ =20 =20 int * diff --git a/gcc/testsuite/gcc.dg/permerror-system.c b/gcc/testsuite/gcc.dg= /permerror-system.c index bd923138461..790e4f03d66 100644 --- a/gcc/testsuite/gcc.dg/permerror-system.c +++ b/gcc/testsuite/gcc.dg/permerror-system.c @@ -17,6 +17,8 @@ /* { dg-error "type of 'i' defaults to 'int' \\\[-Wimplicit-int\\\]" "" { = target *-*-*} 16 } */ /* { dg-error "type defaults to 'int' in type name \\\[-Wimplicit-int\\\]"= "" { target *-*-* } 19 } */ =20 +/* { dg-error "parameter names \\\(without types\\\) in function declarati= on \\\[-Wdeclaration-missing-parameter-type\\\]" "" { target *-*-* } 22 } *= / + /* { dg-error "pointer/integer type mismatch in conditional expression \\\= [-Wint-conversion\\\]" "" { target *-*-* } 29 } */ /* { dg-error "pointer/integer type mismatch in conditional expression \\\= [-Wint-conversion\\\]" "" { target *-*-* } 30 } */ /* { dg-error "passing argument 1 of 'f2' makes pointer from integer witho= ut a cast \\\[-Wint-conversion\\\]" "" { target *-*-* } 31 } */ --=20 2.42.0