From patchwork Tue Nov 14 17:50:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 165039 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:a59:b0:164:83eb:24d7 with SMTP id 25csp2095275rwb; Tue, 14 Nov 2023 09:52:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IEAEjlIiSLNuyhr3p4Rgzap58hbtEFqHzVG313zDSPv9X90vPnOZ81gpDSiGWm7utemjZza X-Received: by 2002:a05:6871:2211:b0:1e9:ae68:fda1 with SMTP id sc17-20020a056871221100b001e9ae68fda1mr12422614oab.1.1699984365088; Tue, 14 Nov 2023 09:52:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699984365; cv=pass; d=google.com; s=arc-20160816; b=sjkXpMOFGtqGc6Ft9UAdcHTy/5GA7U+LCmtwEa1Mdpv/R+NpqDg21WHOL5PhaoM48c 0OhniP3cX+WFdEQNszOB9Dg3Pts2CydlVNWdAowQK8N6nMFzm6Ul0+05eyo5KYtYuUND abPOs1QBE9d6ItdyGoWwaeU68KpRlPr662zJ3yCj/TMO2OQ5i24tqywkpL9I9j3F3gzd BuRFbnfYwZuliSL6Pf7XZAET95CTwxar+YCSk8f+3R6VtQrHrNFb/4dDjzpOV0k5uutq qUzz8Vr0BxqPyh43d+p3MD/t3f5SLqOhB+CStMEuLyZ9J0F2C2ATTfTyAi5N3cRZpbZr +yEw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:user-agent:date:references:message-id:in-reply-to :subject:cc:to:from:dkim-signature:arc-filter:dmarc-filter :delivered-to; bh=1Y4Sleuic98M9IttE/WLJEygPLPN8J64wWol8FDKJMA=; fh=brrc/l6yGUGxGhv8SjiSoDgfQmQ4atC/Em9G49NRuIw=; b=v4ZTocN+euFncUDKq82oVKJYZ2YQEgCXLzFwG8xvXdx0kxvkB63QRw/W1SLo+QpbDm WeGR174zdyeFZhVln3VLI2UOjVbQaOljJMLe6cWtxOeezKurfIxJjIT+8cpnq75uvE7T PUvkZjwmpAbcJCteuGn6DD6bTOPn0ZKiAJ3UfrYMWNE6bCzyjoMUUOwOmUChf44/cSNh HlwwO4UrqJI+JNFS8J3w3EOhlv30jRDz5YH2oV9U2vUpen3DT1Ve1VxrxlDKzBGLgwsT ZH08BVrPG4osCm1l/1P2sZGPOwxeEB3SXf8iYrK3J9uUlua1uJ6CODb0/IUlBbj9Z6Yh Dvzw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PMBlKXKZ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id p2-20020a05622a00c200b0041cb5262974si6990632qtw.483.2023.11.14.09.52.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 09:52:45 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PMBlKXKZ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 67D8138582AF for ; Tue, 14 Nov 2023 17:52:28 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 F26093857C67 for ; Tue, 14 Nov 2023 17:51:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F26093857C67 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 F26093857C67 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=1699984268; cv=none; b=nfK+xU75Yd9coBjrjupJcXhlS22m8xhZFD99p93vai9Qa3Dh70aF1hdwxnm6y5KHjcPoZTK/D1tJzhGo2/VnGmjjMOUU7vUlhAx/91GKYGCDhFXGzWp2XSmkzjADqYi8zjs0DB16joOXZANpfZfLRqePbkmSRFUukElz1h41XWk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699984268; c=relaxed/simple; bh=WDK7rLsjVLKHt4aNoP0zHF43aLJDXXY1RzG2Fl4jj7s=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=ixPOQnsrBCwmzWc2wwuwOU7IQcVkMQvCKrKtFU0auaMo3fFQo8uX+98POMW5+5A7EFY7AyCHkgFoUCfK/DcO9RM9GcmZOECzkiDBLPfyaf1Ez0oRWoNtGbSPmuuMbm00DWZT5DlDG8vzWxjnhBA55cVHsnJ5YhTp5Eflh1yZegc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699984265; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1Y4Sleuic98M9IttE/WLJEygPLPN8J64wWol8FDKJMA=; b=PMBlKXKZE4v7Gq238HqvBXKiuF5kz+oP/M42u4/lZ39EZsbp8MUuYvujJvE4FCHCzW+RKX kDuC4SbmP8+FtRqLYycywNikUgnV8dZlqmKdmCEAMI6PQAjSWWonJuuUtGlO/f0ytXbVyu DZRUQLaVm3WIMswyEv4KGz4gOoJbxuk= 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-323-t2aqaoWfM-SnmSx53vrxOA-1; Tue, 14 Nov 2023 12:51:02 -0500 X-MC-Unique: t2aqaoWfM-SnmSx53vrxOA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 114C4811E97; Tue, 14 Nov 2023 17:51:02 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 644C6112130B; Tue, 14 Nov 2023 17:51:00 +0000 (UTC) From: Florian Weimer To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, jeffreyalaw@gmail.com, joseph@codesourcery.com, sam@gentoo.org Subject: [PATCH v2 8/8] c: Add new -Wdeclaration-missing-parameter-type permerror In-Reply-To: Message-ID: References: X-From-Line: a5f0cb7b4691598e5f61634f08d162f5d7e90d38 Mon Sep 17 00:00:00 2001 Date: Tue, 14 Nov 2023 18:50:58 +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.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782562805583835570 X-GMAIL-MSGID: 1782562805583835570 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 “void function (int32t);”. gcc/c-family/ * c.opt (Wdeclaration-missing-parameter-type): New. gcc/c/ChangeLog: PR other/44209 * c-decl.cc (grokparms): Issue permerror for OPT_Wdeclaration_missing_parameter_type instead of a pedwarn. gcc/ChangeLog: * doc/invoke.texi (Warning Options): Document -Wdeclaration-missing-parameter-type gcc/testsuite/ChangeLog: * gcc.dg/permerror-default.c (missing_parameter_type): Expect error. * gcc.dg/permerror-fpermissive.c (missing_parameter_type): Expect -Wdeclaration-missing-parameter-type warning. * gcc.dg/permerror-gnu89-pedantic.c (missing_parameter_type): Expect -Wdeclaration-missing-parameter-type error. * gcc.dg/permerror-gnu89.c (missing_parameter_type): Expect -Wdeclaration-missing-parameter-type warning. * gcc.dg/permerror-noerror.c: Add -Wno-error=declaration-missing-parameter-type to build flags. (missing_parameter_type): Expect -Wdeclaration-missing-parameter-type warning. * gcc.dg/permerror-pedantic.c (missing_parameter_type): Expect -Wdeclaration-missing-parameter-type error. --- 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/testsuite/gcc.dg/permerror-fpermissive.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-pedantic.c | 2 +- gcc/testsuite/gcc.dg/permerror-system.c | 2 ++ 10 files changed, 33 insertions(+), 10 deletions(-) diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index b10c6057cd1..723985ec5d0 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. +Wdeclaration-missing-parameter-type +C ObjC Warning +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) { - pedwarn (input_location, 0, "parameter names (without types) in " - "function declaration"); + permerror_opt (input_location, + OPT_Wdeclaration_missing_parameter_type, + "parameter names (without types) in " + "function declaration"); arg_info->parms = NULL_TREE; } else diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index c492ef7ba0c..66804bfe120 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -502,7 +502,8 @@ Objective-C and Objective-C++ Dialects}. @item C and Objective-C-only Warning Options @gccoptlist{-Wbad-function-cast -Wmissing-declarations --Wmissing-parameter-type -Wmissing-prototypes -Wmissing-variable-declarations +-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} @@ -9732,6 +9733,20 @@ void foo(bar) @{ @} This warning is also enabled by @option{-Wextra}. +@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=declaration-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.dg/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 \\\[-Wimplicit-int\\\]" } */ } -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-parameter-type\\\]" } */ int * diff --git a/gcc/testsuite/gcc.dg/permerror-fpermissive.c b/gcc/testsuite/gcc.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 \\\[-Wimplicit-int\\\]" } */ } -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-parameter-type\\\]" } */ int * diff --git a/gcc/testsuite/gcc.dg/permerror-gnu89-pedantic.c b/gcc/testsuite/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" } */ } -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-parameter-type\\\]" } */ 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" } */ } -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-parameter-type\\\]" } */ int * diff --git a/gcc/testsuite/gcc.dg/permerror-noerror.c b/gcc/testsuite/gcc.dg/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=implicit-function-declaration -Wno-error=implicit-int -Wno-error=int-conversion -Wno-error=incompatible-pointer-types -Wno-error=return-mismatch" } */ +/* { dg-options "-Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=int-conversion -Wno-error=incompatible-pointer-types -Wno-error=return-mismatch -Wno-error=declaration-missing-parameter-type" } */ /* This test should emulate the effect of -fpermissive by adding all the -Wno-error= 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 \\\[-Wimplicit-int\\\]" } */ } -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-parameter-type\\\]" } */ int * 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 \\\[-Wimplicit-int\\\]" } */ } -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-parameter-type\\\]" } */ 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 } */ +/* { dg-error "parameter names \\\(without types\\\) in function declaration \\\[-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 without a cast \\\[-Wint-conversion\\\]" "" { target *-*-* } 31 } */