From patchwork Tue Sep 12 17:30:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1833131 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=FYfx+mGf; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RlVxC44T9z1ygM for ; Wed, 13 Sep 2023 03:31:11 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 57EDB3858288 for ; Tue, 12 Sep 2023 17:31:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 57EDB3858288 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694539869; bh=Yr0cylHdtFLIw5ujkqj2Idb1uQj4b7fhCC81OXQkpC4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=FYfx+mGfWybkp5TEmJL6w99rICFZ+XUvgHi56bdoyW4TKRoZhKnndsPA+m+gwq04J skR5RXkAoWbdAgPgScvyCPdAwiwNPB7J0k6jiTO+tNpZ5RbjWf6EWn9H1qJW7qzZ8P 9ybMSOdN0Im65Py1b0N0aTkeUA42jj58cFAgMVKQ= 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 3C4E43858C50 for ; Tue, 12 Sep 2023 17:30:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3C4E43858C50 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-473-kSYT_Ap3Puq4cwv4Z-HGWg-1; Tue, 12 Sep 2023 13:30:43 -0400 X-MC-Unique: kSYT_Ap3Puq4cwv4Z-HGWg-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-76e26652e6fso707051885a.2 for ; Tue, 12 Sep 2023 10:30:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694539843; x=1695144643; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Yr0cylHdtFLIw5ujkqj2Idb1uQj4b7fhCC81OXQkpC4=; b=k6UWEBKo9+Adji8FaEIgzi/80/nIW5zpi0exrWy0xCkG5LEOs86tFwHTykItX0y/n8 qTBqoPZ9Dq0iGdO5qiLW8rnsx3oO3ie1bPbQIXIw9MYU+R6xtaiIzU4RlgURtiPDtu+p 7mFSdIIsHiBehGTK/TZezmcSOj9NBiI86r9afmh5jAE9cXz6xSDepZnHR1Tp96Ti2vuR NzJ9YycpUJiOz50mCIiNMeO13KxOeuLoyUzAzhiQ525FW4vp0aNcb+6pgkCRbsECbdBF Sa2FdK4G4KQp+KktHmi6R5eucqF8UO03E93mwNlu8Xc/oSD04255bX09DYZEEYGRmST+ Hflw== X-Gm-Message-State: AOJu0YwAKQgbTjAevHEGGkyLU2DPIGAguY527Bto9fNerWFx0zCLu6Vz joua9YqFwaLtkrXQCFHPYoZFxhDpDKGODk3QUxjHKpeN41ViMaoyJ5DYRVHCxXBSQrFUMfMrGDH fBoPESftAmAItrEgiAtsiXR2cfiGGy+fu2y+9/V2LIqQ7ZlyMbxCRJ6vkEv0KDf+ZA0323/IsbQ == X-Received: by 2002:a05:620a:17a7:b0:76d:b2d9:ae4b with SMTP id ay39-20020a05620a17a700b0076db2d9ae4bmr62840qkb.13.1694539842757; Tue, 12 Sep 2023 10:30:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG4v/jn4WememK6rrmT55Pb6TqLxyaegPvuTnVzAWwTBQ65FfpK9aTOqXGSMlKyPLvRxP5ZRg== X-Received: by 2002:a05:620a:17a7:b0:76d:b2d9:ae4b with SMTP id ay39-20020a05620a17a700b0076db2d9ae4bmr62812qkb.13.1694539842385; Tue, 12 Sep 2023 10:30:42 -0700 (PDT) Received: from jason.com (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id c28-20020ac86e9c000000b004108fe9697asm3403377qtv.61.2023.09.12.10.30.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 10:30:39 -0700 (PDT) To: gcc-patches@gcc.gnu.org, David Malcolm Subject: [PATCH RFC] diagnostic: add permerror variants with opt Date: Tue, 12 Sep 2023 13:30:36 -0400 Message-Id: <20230912173036.1930553-1-jason@redhat.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.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 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: , X-Patchwork-Original-From: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Tested x86_64-pc-linux-gnu. Does this approach make sense to you? Or do you have another idea? Perhaps the warn_system_headers adjustment should also be part of this? -- 8< -- In the discussion of promoting some pedwarns to be errors by default, rather than move them all into -fpermissive it seems to me to make sense to follow the -Wnarrowing pattern of turning pedantic_errors on by default for them like I've previously done for -Wnarrowing. This way will also work with -fpermissive, but users can still use -Wno-error=narrowing to downgrade that specific diagnostic rather than everything affected by -fpermissive. gcc/ChangeLog: * diagnostic.cc (permerror): Add new overloads. * diagnostic-core.h (permerror): Declare them. gcc/cp/ChangeLog: * typeck2.cc (check_narrowing): Use permerror. --- gcc/diagnostic-core.h | 3 +++ gcc/cp/typeck2.cc | 9 +++------ gcc/diagnostic.cc | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 6 deletions(-) base-commit: f73d2d61a5926f42e9e5d771d23868787ef9d800 diff --git a/gcc/diagnostic-core.h b/gcc/diagnostic-core.h index c9e27fd2e6e..2d9909f18bd 100644 --- a/gcc/diagnostic-core.h +++ b/gcc/diagnostic-core.h @@ -105,6 +105,9 @@ extern bool pedwarn (rich_location *, int, const char *, ...) extern bool permerror (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3); extern bool permerror (rich_location *, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3); +extern bool permerror (location_t, int, const char *, ...) ATTRIBUTE_GCC_DIAG(3,4); +extern bool permerror (rich_location *, int, const char *, + ...) ATTRIBUTE_GCC_DIAG(3,4); extern void sorry (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2); extern void sorry_at (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3); extern void inform (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3); diff --git a/gcc/cp/typeck2.cc b/gcc/cp/typeck2.cc index cd1ea045720..1cbab70f513 100644 --- a/gcc/cp/typeck2.cc +++ b/gcc/cp/typeck2.cc @@ -1109,15 +1109,12 @@ check_narrowing (tree type, tree init, tsubst_flags_t complain, else if (complain & tf_error) { int savederrorcount = errorcount; - if (!flag_permissive) - global_dc->pedantic_errors = 1; auto s = make_temp_override (global_dc->dc_warn_system_headers, true); - pedwarn (loc, OPT_Wnarrowing, - "narrowing conversion of %qE from %qH to %qI", - init, ftype, type); + permerror (loc, OPT_Wnarrowing, + "narrowing conversion of %qE from %qH to %qI", + init, ftype, type); if (errorcount == savederrorcount) ok = true; - global_dc->pedantic_errors = flag_pedantic_errors; } } diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc index 65c0cfbf11a..4195a01aa09 100644 --- a/gcc/diagnostic.cc +++ b/gcc/diagnostic.cc @@ -2054,6 +2054,45 @@ permerror (rich_location *richloc, const char *gmsgid, ...) return ret; } +/* Similar to the above, but controlled by a flag other than -fpermissive. + As above, an error by default or a warning with -fpermissive, but this + diagnostic can also be downgraded by -Wno-error=opt. */ + +bool +permerror (location_t location, int opt, const char *gmsgid, ...) +{ + auto_diagnostic_group d; + va_list ap; + va_start (ap, gmsgid); + rich_location richloc (line_table, location); + bool pe = global_dc->pedantic_errors; + if (!global_dc->permissive) + global_dc->pedantic_errors = true; + bool ret = diagnostic_impl (&richloc, NULL, opt, gmsgid, &ap, DK_PEDWARN); + global_dc->pedantic_errors = pe; + va_end (ap); + return ret; +} + +/* Same as "permerror" above, but at RICHLOC. */ + +bool +permerror (rich_location *richloc, int opt, const char *gmsgid, ...) +{ + gcc_assert (richloc); + + auto_diagnostic_group d; + va_list ap; + va_start (ap, gmsgid); + bool pe = global_dc->pedantic_errors; + if (!global_dc->permissive) + global_dc->pedantic_errors = true; + bool ret = diagnostic_impl (richloc, NULL, opt, gmsgid, &ap, DK_PEDWARN); + global_dc->pedantic_errors = pe; + va_end (ap); + return ret; +} + /* A hard error: the code is definitely ill-formed, and an object file will not be produced. */ void