From patchwork Tue Nov 15 00:33:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 20107 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2440625wru; Mon, 14 Nov 2022 16:34:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf73PWweT7kdu1lYNbBF88nq3ZDZ+yDk+YVLUCzGOPn/p/rsD8BSLnvmWM9YEaJwqOQ/jHEo X-Received: by 2002:a17:906:71d8:b0:7ad:b45c:dbe1 with SMTP id i24-20020a17090671d800b007adb45cdbe1mr12152028ejk.726.1668472477325; Mon, 14 Nov 2022 16:34:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668472477; cv=none; d=google.com; s=arc-20160816; b=hr6LvQpoCLvi8uInfH7UGFCOPpRlEoWG6UvJlIQ5gYp7nKvUMoDTyD4c7gsJHHVAOc s3kIDhi2Y48sUCFh4sdIDaz+5e93exqa4y3lEo/95/3xkYeqYoiUKMyc5GUUqqvoZbkB bSE3p4RBmTnGWVtXmHo3nZ+WwNXN5CJrRLLw7U+hKZ53iEU9NOmTkH/QuOADxOc69H5J vP+zhm97L0rYBt9AS69U2wdtL2P/q0+J8pdrtk4NVCU1Ig70bNR+JQdVmcPVtgmSqkde slsv7O/FOJfPHlShIBWVNM4839iFtsnXEaXtHUNHPTbAVPWk/5WP09JCKZlD0+Pu+Vpk xiAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:user-agent:in-reply-to:mime-version:references :message-id:subject:cc:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=YewhL0RKRBMrEE76GbwjrdXhFvWNaK/9t87KdWxO87k=; b=oZpJsGNHWaUj2sQANmBi3jCA7DrGLTI4izFBvPBDSlohm+mM9PCgQwjzRirWNkd+GR 5Jtg/zE9ZpyOUKH1d3tvt/LOf8Ywp5IHkeQlSnjfHG0zVh/rjEspzgk14UvdwnLmJL5+ k3z4pl1aItcFE8BXKIRasjRiKoVx/ixXbiBpQy861F7vh0wxmTxw2wazq3cMz2PEO3pM 3ayCcyKjD7IqMv92jKzKcKd9sEO3a53X6oNtxruwZWrOrYNLEQhKn8RP5NsdAkapvZ9M Xj1fiB+E3IQITOdfHWECFTp4NmheC3Tx7XAkuLCOZk6r7TVPS1vJjhIT+IwmwFvJHp2a 1VVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=tCyMJz+o; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id sh31-20020a1709076e9f00b007adadfc97c7si11080307ejc.918.2022.11.14.16.34.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 16:34:37 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=tCyMJz+o; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 56BBA3858C60 for ; Tue, 15 Nov 2022 00:34:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 56BBA3858C60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668472476; bh=YewhL0RKRBMrEE76GbwjrdXhFvWNaK/9t87KdWxO87k=; h=Date:To:Cc:Subject:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=tCyMJz+o9Jnefaoa4FYwMU6sPjn13Idbr0TXpH/8PAWP66tcQ4Ay5LpL7BmlsjrNK 1ngG+LJqjYQBwWW6invCKutnIyzxSXtENoyfumgGxzEuxOk30WH5b6tQb390jRmsRy Ftnswa3mJoApHyBhLXdHxx96rtMpLp7ilq3mfm3U= 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 E489A3858C60 for ; Tue, 15 Nov 2022 00:33:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E489A3858C60 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-613-zGdIO0q0OGmI3R_DktZD9Q-1; Mon, 14 Nov 2022 19:33:51 -0500 X-MC-Unique: zGdIO0q0OGmI3R_DktZD9Q-1 Received: by mail-qt1-f200.google.com with SMTP id ew11-20020a05622a514b00b003a524196d31so9074567qtb.2 for ; Mon, 14 Nov 2022 16:33:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YewhL0RKRBMrEE76GbwjrdXhFvWNaK/9t87KdWxO87k=; b=6175gV4rimW9+7fdiJ2b7i+uC1HONeMg4blzOeCMRh1KQt09I7CZXwZFdhAygEUY2n +Q5M7KrVqdfGiGfhH4Zwyo/j3LX7OgUcMhMrajLCqvOHMb5QSX2iGc5GsX8BtLyXdzLz ackKOxtH0o/imfz3+toCGvj8xO6C6VDeCJlHyi5VimC+kvb6+huKEKipvGojj4raL1Dn 3QAP2v/6p5BqkTq9C7s/hWyNqJ4lY8vimQ7vpWmfZNLcLiHLiFK6mC0u/oQwEv4PdccH +5IvrhEi1GgZuIuTAJ/YRJzHBRHtXAD7OS0sO42e0IEpBums2ouX3yoUgRH2f8OcuddO QNUA== X-Gm-Message-State: ANoB5pmwUmc0afdjPPV4s5ssJsPshMfPA8ZyK/5FxqoyfTLdDmEHRKIJ G1ICYNJmKfmd01xQ0Rwn9z9/6IDe0yC5J8fM5TogRPHRccCBrBWkB5tFNhEb1lZXyEEigeEZXqB 4EOW1hqHQeBG6Fcor2g== X-Received: by 2002:a05:622a:1dcd:b0:3a5:a2:3486 with SMTP id bn13-20020a05622a1dcd00b003a500a23486mr14705567qtb.560.1668472430649; Mon, 14 Nov 2022 16:33:50 -0800 (PST) X-Received: by 2002:a05:622a:1dcd:b0:3a5:a2:3486 with SMTP id bn13-20020a05622a1dcd00b003a500a23486mr14705556qtb.560.1668472430418; Mon, 14 Nov 2022 16:33:50 -0800 (PST) Received: from redhat.com (2603-7000-9500-2e39-0000-0000-0000-1db4.res6.spectrum.com. [2603:7000:9500:2e39::1db4]) by smtp.gmail.com with ESMTPSA id cq10-20020a05622a424a00b003a5fb681ae7sm127674qtb.3.2022.11.14.16.33.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 16:33:49 -0800 (PST) Date: Mon, 14 Nov 2022 19:33:47 -0500 To: Jason Merrill Cc: GCC Patches Subject: [PATCH v2] c++: Disable -Wignored-qualifiers for template args [PR107492] Message-ID: References: <20221101170156.52672-1-polacek@redhat.com> <8278b3b0-6af7-8c1a-0aad-a093419d7672@redhat.com> MIME-Version: 1.0 In-Reply-To: <8278b3b0-6af7-8c1a-0aad-a093419d7672@redhat.com> User-Agent: Mutt/2.2.7 (2022-08-07) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-12.2 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_H2, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Marek Polacek via Gcc-patches From: Marek Polacek Reply-To: Marek Polacek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748314106917531563?= X-GMAIL-MSGID: =?utf-8?q?1749520196753347275?= On Thu, Nov 03, 2022 at 03:22:12PM -0400, Jason Merrill wrote: > On 11/1/22 13:01, Marek Polacek wrote: > > It seems wrong to issue a -Wignored-qualifiers warning for code like: > > > > static_assert(!is_same_v); > > > > because there the qualifier matters. Likewise in template > > specialization: > > > > template struct S { }; > > template<> struct S { }; > > template<> struct S { }; // OK, not a redefinition > > > > I'm of the mind that we should disable the warning for template > > arguments, as in the patch below. > > Hmm, I'm not sure why we would want to treat template arguments differently > from other type-ids. Maybe only warn if funcdecl_p? I think that makes sense. There are other contexts in which cv-quals matter, for instance trailing-return-type. Updated patch below, plus I've extended the testcase. Thanks, Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? -- >8 -- It seems wrong to issue a -Wignored-qualifiers warning for code like: static_assert(!is_same_v); because there the qualifier matters. Likewise in template specialization: template struct S { }; template<> struct S { }; template<> struct S { }; // OK, not a redefinition And likewise in other type-id contexts such as trailing-return-type: auto g() -> const void (*)(); This patch limits the warning to the function declaration context only. PR c++/107492 gcc/cp/ChangeLog: * decl.cc (grokdeclarator): Only emit a -Wignored-qualifiers warning when funcdecl_p. gcc/testsuite/ChangeLog: * g++.dg/warn/Wignored-qualifiers3.C: New test. --- gcc/cp/decl.cc | 6 ++++- .../g++.dg/warn/Wignored-qualifiers3.C | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wignored-qualifiers3.C base-commit: c41bbfcaf9d6ef5b57a7e89bba70b861c08a686b diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 890cfcabd35..67b9f24d7d6 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -13038,7 +13038,11 @@ grokdeclarator (const cp_declarator *declarator, if (type_quals != TYPE_UNQUALIFIED) { - if (SCALAR_TYPE_P (type) || VOID_TYPE_P (type)) + /* It's wrong, for instance, to issue a -Wignored-qualifiers + warning for + static_assert(!is_same_v); + because there the qualifier matters. */ + if (funcdecl_p && (SCALAR_TYPE_P (type) || VOID_TYPE_P (type))) warning_at (typespec_loc, OPT_Wignored_qualifiers, "type " "qualifiers ignored on function return type"); /* [dcl.fct] "A volatile-qualified return type is diff --git a/gcc/testsuite/g++.dg/warn/Wignored-qualifiers3.C b/gcc/testsuite/g++.dg/warn/Wignored-qualifiers3.C new file mode 100644 index 00000000000..dedb38fc995 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wignored-qualifiers3.C @@ -0,0 +1,24 @@ +// PR c++/107492 +// { dg-do compile { target c++14 } } +// { dg-additional-options "-Wignored-qualifiers" } + +// Here the 'const' matters, so don't warn. +template struct S { }; +template<> struct S { }; +template<> struct S { }; // { dg-bogus "ignored" } + +template constexpr bool is_same_v = false; +template constexpr bool is_same_v = true; + +static_assert( ! is_same_v< void(*)(), const void(*)() >, ""); // { dg-bogus "ignored" } + +// Here the 'const' matters as well -> don't warn. +auto g() -> const void (*)(); // { dg-bogus "ignored" } +auto g() -> const void (*)() { return nullptr; } // { dg-bogus "ignored" } + +// Here as well. +const void (*h)() = static_cast(h); // { dg-bogus "ignored" } + +// But let's keep the warning here. +const void f(); // { dg-warning "ignored" } +const void f() { } // { dg-warning "ignored" }