From patchwork Mon Nov 13 13:11:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 164474 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1190191vqg; Mon, 13 Nov 2023 05:11:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IE9acSkrA+YfHrTllPWPvFYghN5zI3T+3D1aYcVRpr4aRXFC/aoKxzz4IcoFRskwt632bIa X-Received: by 2002:a05:620a:2914:b0:778:b72d:6518 with SMTP id m20-20020a05620a291400b00778b72d6518mr7752931qkp.35.1699881104359; Mon, 13 Nov 2023 05:11:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699881104; cv=pass; d=google.com; s=arc-20160816; b=bySD+6HkxsSD0iwwTaQj1VP/n0PumnCYcGxxOB+FcLsqkcgHLlqwHrp74xrcUHb1O0 MljFM+ErwOvldnoiUu0bVLEycDUR1nVWsk+ZAUq6OVlIoxAtSSDg8bcXkrTn/GX4W6rM gLJLJ5grxJ10diq8UFZUnxzW5gNYqprxKo7EFvh0y7kieTm/C8VMQ6qhTO2bcE+s/YlA BNmEg5FXI02a+Nh/gGiheJHTech3x39qiBfyHvAiQZbb0jOJBS80BdVt2XzjncYFAW5u SVn7v0UsUyxtI06DW2XNp2j4yjFXIwpk7r0zLEGdC+uVSDkKlyMlRVoSd/qc9dRyUCum OC7A== 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:to:from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=953E8EgiO8wK06j2cGoNse4m69kMqmP1W4vlMj01P2w=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=V9KryDTvxOX/39QIQdFoIn+5HPw0U1h2tmog/TnlFgqsl8cTkUsRCW1miMD0mfotcd NmQQpQraGT8ywLXAncGjrKwURppjU9tI2OOWu8WGtXQS94O0dHDj3cit1wt27jgE0sgF P6DWBKFVIZelfSBWf7G490qSALvZP6nuEHDgXpys7TB6XiApUQlHm32IiO8Um3t6UDZc FVZdEionLUombDkFk7f1VTkNTteGdF6Qd8k01l9U+t7xZdo5hAThzlC8hkeE28eTjAPA pSMxWvhQSxpwybtbSH57WPU6kvDFZY/K0mXqzSb2/JegW7MRFPSTS4IH6d65x1zZUP70 /BFg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Cpr8Cr0o; 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 o14-20020a05620a2a0e00b007742b023d3esi4858399qkp.99.2023.11.13.05.11.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Nov 2023 05:11:44 -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=Cpr8Cr0o; 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 B6BF83883008 for ; Mon, 13 Nov 2023 13:11:36 +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.133.124]) by sourceware.org (Postfix) with ESMTPS id 2C4A73861894 for ; Mon, 13 Nov 2023 13:11:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2C4A73861894 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 2C4A73861894 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699881071; cv=none; b=j000P9hY4YX8S8Gd5dxpBuEVO8uLd48cStz7gUoroJXuDA5/tcZTQfKGL0nmmLpYCkW0LM0CyKXEpJXds6oulPYQFvBJ2uZD+RGyPF5MlB3i2tdAqXDg4J+I3WpZ6wx+yUiRtKiF+JGDiF/qcgpjEM2vSpciVv7cYHfV9WaF04U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699881071; c=relaxed/simple; bh=+NY3tomtrPc/AVAMP3vKI/frnRGUG8l9a+XKdPm1mjE=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=FG/GL9zpyRrJNfBMhP04HUWvbKX+iJ1hcL0RC1eZOKAo8ayk8G7BhaYx2NKeBU7I0nZsnd26QtoWU6cys+aorgMnBKRY/ioJR795NFZ/Dy7z15JZrWhIA/GWSEWko9RpX0a/kf+5Xs4WiDVTFlUeDhN/iM5cPfVmKq5lXltBfXo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699881068; 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=953E8EgiO8wK06j2cGoNse4m69kMqmP1W4vlMj01P2w=; b=Cpr8Cr0oikhzOIimjNbNCwpjCc4u7gwAOagbT2bcY4zG81qT3JVuWl3sSniK5E3rYcMt/o K1fEqEaHVhVL84qWcbpLPRSVr8Ypplx1GFz6uPRvKdCoYvOeuPBtBy9Y9NRLcodqUjWfcX YURNGAZ+9fy09KBbzd3qdwnIA3lBjKE= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-434-EKAIlt2lP_i48Oaghg8QbA-1; Mon, 13 Nov 2023 08:11:07 -0500 X-MC-Unique: EKAIlt2lP_i48Oaghg8QbA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 7A7522810D49 for ; Mon, 13 Nov 2023 13:11:07 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B936B3D3 for ; Mon, 13 Nov 2023 13:11:06 +0000 (UTC) From: Florian Weimer To: gcc-patches@gcc.gnu.org Subject: [PATCH 4/6] c: Turn -Wimplicit-int into a pedpermerror In-Reply-To: Message-ID: <309d163cd3eff4b3fbe9be5198443ccf231d65ba.1699879818.git.fweimer@redhat.com> References: X-From-Line: 309d163cd3eff4b3fbe9be5198443ccf231d65ba Mon Sep 17 00:00:00 2001 Date: Mon, 13 Nov 2023 14:11:05 +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.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.8 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_H3, 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: 1782454528465777441 X-GMAIL-MSGID: 1782454528465777441 There is a missed opportunity here to issue spelling diagnostics in prototype declarations (e.g., for “extern int foo (int32t);”). gcc/ * doc/invoke.texi (Warning Options): Document changes. gcc/c/ * c-decl.cc (warn_defaults_to): Call emit_diagnostic_valist instead of reimplementing it. Issue a pedpermerror for C99 and later. (store_parm_decls_oldstyle): Call pedpermerror for OPT_Wimplicit_int. gcc/testsuite/ * gcc.dg/Wimplicit-int-1.c: Compile with -fpermissive due to expected warning. * gcc.dg/Wimplicit-int-4.c: Likewise. * gcc.dg/Wimplicit-int-1a.c: New test. Copied from gcc.dg/Wimplicit-int-1.c, but expect errors. * gcc.dg/Wimplicit-int-4a.c: New test. Copied from gcc.dg/Wimplicit-int-4.c, but expect errors. * gcc.dg/gnu23-attr-syntax-2.c: Compile with -fpermissive due to expected implicit-int error. * gcc.dg/gnu23-attr-syntax-3.c: New test. Copied from gcc.dg/gnu23-attr-syntax-2.c, but expect an error. * gcc.dg/pr105635.c: Build with -fpermissive due to implicit int. * gcc.dg/pr105635-2.c: New test. Copied from gcc.dg/pr105635.c. Expect implicit int error. * gcc.dg/noncompile/pr79758.c: Build with -fpermissive due to implicit int. * gcc.dg/noncompile/pr79758-2.c: New test. Copied from gcc.dg/noncompile/pr79758.c. Expect implicit int error. --- gcc/c/c-decl.cc | 20 +++++++++++--------- gcc/doc/invoke.texi | 7 +++++-- gcc/testsuite/gcc.dg/Wimplicit-int-1.c | 2 +- gcc/testsuite/gcc.dg/Wimplicit-int-1a.c | 11 +++++++++++ gcc/testsuite/gcc.dg/Wimplicit-int-4.c | 2 +- gcc/testsuite/gcc.dg/Wimplicit-int-4a.c | 11 +++++++++++ gcc/testsuite/gcc.dg/gnu23-attr-syntax-2.c | 2 +- gcc/testsuite/gcc.dg/gnu23-attr-syntax-3.c | 17 +++++++++++++++++ gcc/testsuite/gcc.dg/noncompile/pr79758-2.c | 6 ++++++ gcc/testsuite/gcc.dg/noncompile/pr79758.c | 1 + gcc/testsuite/gcc.dg/pr105635-2.c | 11 +++++++++++ gcc/testsuite/gcc.dg/pr105635.c | 2 +- 12 files changed, 77 insertions(+), 15 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/Wimplicit-int-1a.c create mode 100644 gcc/testsuite/gcc.dg/Wimplicit-int-4a.c create mode 100644 gcc/testsuite/gcc.dg/gnu23-attr-syntax-3.c create mode 100644 gcc/testsuite/gcc.dg/noncompile/pr79758-2.c create mode 100644 gcc/testsuite/gcc.dg/pr105635-2.c diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index e8387bfa984..f787d213cfe 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -6577,16 +6577,18 @@ warn_defaults_to (location_t location, int opt, const char *gmsgid, ...) { diagnostic_info diagnostic; va_list ap; - rich_location richloc (line_table, location); + diagnostic_t kind; va_start (ap, gmsgid); - diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, - flag_isoc99 ? DK_PEDWARN : DK_WARNING); - diagnostic.option_index = opt; - diagnostic_report_diagnostic (global_dc, &diagnostic); + if (flag_isoc99 && !flag_pedantic_errors && opt) + kind = DK_PERMERROR; + else if (flag_isoc99) + kind = DK_PEDWARN; + else + kind = DK_WARNING; + emit_diagnostic_valist (kind, location, opt, gmsgid, &ap); va_end (ap); } - /* Returns the smallest location != UNKNOWN_LOCATION in LOCATIONS, considering only those c_declspec_words found in LIST, which must be terminated by cdw_number_of_elements. */ @@ -10635,9 +10637,9 @@ store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info) warn_if_shadowing (decl); if (flag_isoc99) - pedwarn (DECL_SOURCE_LOCATION (decl), - OPT_Wimplicit_int, "type of %qD defaults to %", - decl); + pedpermerror (DECL_SOURCE_LOCATION (decl), + OPT_Wimplicit_int, "type of %qD defaults to %", + decl); else warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wmissing_parameter_type, diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 1a15af29f01..3a1b9b00f24 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -6180,6 +6180,7 @@ that have their own flag: @gccoptlist{ -Wimplicit-function-declaration @r{(C)} +-Wimplicit-int @r{(C)} -Wint-conversion @r{(C)} -Wnarrowing @r{(C++)} } @@ -6851,8 +6852,10 @@ This warning is enabled by @option{-Wall} in C++. @opindex Wno-implicit-int @item -Wno-implicit-int @r{(C and Objective-C only)} This option controls warnings when a declaration does not specify a type. -This warning is enabled by default in C99 and later dialects of C, -and also by @option{-Wall}. +This warning is enabled by default, as an error, in C99 and later +dialects of C, and also by @option{-Wall}. 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=implicit-int}. This warning is upgraded to an error by @option{-pedantic-errors}. diff --git a/gcc/testsuite/gcc.dg/Wimplicit-int-1.c b/gcc/testsuite/gcc.dg/Wimplicit-int-1.c index 4a96e8f505d..fc7726c517e 100644 --- a/gcc/testsuite/gcc.dg/Wimplicit-int-1.c +++ b/gcc/testsuite/gcc.dg/Wimplicit-int-1.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "" } */ +/* { dg-options "-fpermissive" } */ static l; /* { dg-warning "type defaults to" } */ diff --git a/gcc/testsuite/gcc.dg/Wimplicit-int-1a.c b/gcc/testsuite/gcc.dg/Wimplicit-int-1a.c new file mode 100644 index 00000000000..ef1835e2d3a --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wimplicit-int-1a.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "" } */ + +static l; /* { dg-error "type defaults to" } */ + +foo (a) /* { dg-error "return type defaults to" } */ +/* { dg-error "type of .a. defaults to .int." "type" { target *-*-* } .-1 } */ +{ + auto p; /* { dg-error "type defaults to" } */ + typedef bar; /* { dg-error "type defaults to" } */ +} diff --git a/gcc/testsuite/gcc.dg/Wimplicit-int-4.c b/gcc/testsuite/gcc.dg/Wimplicit-int-4.c index c9c6e8e5e95..99c61a76ecf 100644 --- a/gcc/testsuite/gcc.dg/Wimplicit-int-4.c +++ b/gcc/testsuite/gcc.dg/Wimplicit-int-4.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-Wno-implicit -Wimplicit-int" } */ +/* { dg-options "-fpermissive -Wno-implicit -Wimplicit-int" } */ static l; /* { dg-warning "type defaults to" } */ diff --git a/gcc/testsuite/gcc.dg/Wimplicit-int-4a.c b/gcc/testsuite/gcc.dg/Wimplicit-int-4a.c new file mode 100644 index 00000000000..920a088f02b --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wimplicit-int-4a.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-Wno-implicit -Wimplicit-int" } */ + +static l; /* { dg-error "type defaults to" } */ + +foo (a) /* { dg-error "return type defaults to" } */ +/* { dg-error "type of .a. defaults to .int." "type" { target *-*-* } .-1 } */ +{ + auto p; /* { dg-error "type defaults to" } */ + typedef bar; /* { dg-error "type defaults to" } */ +} diff --git a/gcc/testsuite/gcc.dg/gnu23-attr-syntax-2.c b/gcc/testsuite/gcc.dg/gnu23-attr-syntax-2.c index ba60f7a095a..8943534f2b2 100644 --- a/gcc/testsuite/gcc.dg/gnu23-attr-syntax-2.c +++ b/gcc/testsuite/gcc.dg/gnu23-attr-syntax-2.c @@ -1,7 +1,7 @@ /* Test C23 attribute syntax. Invalid uses of attributes with GNU C features. */ /* { dg-do compile } */ -/* { dg-options "-std=gnu23 -w" } */ +/* { dg-options "-fpermissive -std=gnu23 -w" } */ /* Attributes cannot be used as prefix attributes on old-style parameter declarations or on function declarators with identifier diff --git a/gcc/testsuite/gcc.dg/gnu23-attr-syntax-3.c b/gcc/testsuite/gcc.dg/gnu23-attr-syntax-3.c new file mode 100644 index 00000000000..d73d6a3cfa8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/gnu23-attr-syntax-3.c @@ -0,0 +1,17 @@ +/* Test C23 attribute syntax. Invalid uses of attributes with GNU C + features. Non-permissive variant. */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu23 -w" } */ + +/* Attributes cannot be used as prefix attributes on old-style + parameter declarations or on function declarators with identifier + lists (removed from C23). */ + +void (*f(a, b) [[]])() int a, b; { } /* { dg-error "expected" } */ + +void f(x, y) int x; [[]] int y; { } /* { dg-error "expected" } */ +/* { dg-error "type of 'y' defaults to 'int'" "" { target *-*-* } .-1 } */ + +/* Nonempty attributes cannot be used as postfix attributes with + __auto_type. */ +__auto_type [[gnu::no_such_attr]] x = 1; /* { dg-error "'__auto_type' followed by" } */ diff --git a/gcc/testsuite/gcc.dg/noncompile/pr79758-2.c b/gcc/testsuite/gcc.dg/noncompile/pr79758-2.c new file mode 100644 index 00000000000..e6a27f952ef --- /dev/null +++ b/gcc/testsuite/gcc.dg/noncompile/pr79758-2.c @@ -0,0 +1,6 @@ +/* PR c/79758 */ +/* { dg-do compile } */ + +void fn1 (int[a]) { }; /* { dg-error "undeclared here" } */ +void fn1 (b) { }; /* { dg-error "redefinition" } */ +/* { dg-error "defaults to 'int'" "" { target *-*-* } .-1 } */ diff --git a/gcc/testsuite/gcc.dg/noncompile/pr79758.c b/gcc/testsuite/gcc.dg/noncompile/pr79758.c index a31216068f0..e42a44380fa 100644 --- a/gcc/testsuite/gcc.dg/noncompile/pr79758.c +++ b/gcc/testsuite/gcc.dg/noncompile/pr79758.c @@ -1,5 +1,6 @@ /* PR c/79758 */ /* { dg-do compile } */ +/* { dg-additional-options "-fpermissive" } */ void fn1 (int[a]) { }; /* { dg-error "undeclared here" } */ void fn1 (b) { }; /* { dg-error "redefinition" } */ diff --git a/gcc/testsuite/gcc.dg/pr105635-2.c b/gcc/testsuite/gcc.dg/pr105635-2.c new file mode 100644 index 00000000000..807eef0b7cd --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr105635-2.c @@ -0,0 +1,11 @@ +/* PR c/105635 */ +/* { dg-do compile } */ +/* { dg-options "-Wall" } */ + +void foo (int, int[*]); /* { dg-message "previous declaration of 'foo' with type" } */ + +foo (int x, int y) /* { dg-error "return type defaults to 'int'" } */ +{ /* { dg-warning "conflicting types for 'foo'" "" { target *-*-* } .-1 } */ + /* { dg-message "declared here" "" { target *-*-* } .-2 } */ + return (x >= 0) != (y < 0); /* { dg-warning "'return' with a value, in function returning void" } */ +} diff --git a/gcc/testsuite/gcc.dg/pr105635.c b/gcc/testsuite/gcc.dg/pr105635.c index aa02f593bfa..b98ea1b3c3b 100644 --- a/gcc/testsuite/gcc.dg/pr105635.c +++ b/gcc/testsuite/gcc.dg/pr105635.c @@ -1,6 +1,6 @@ /* PR c/105635 */ /* { dg-do compile } */ -/* { dg-options "-Wall" } */ +/* { dg-options "-fpermissive -Wall" } */ void foo (int, int[*]); /* { dg-message "previous declaration of 'foo' with type" } */