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 E489A3858C60 for ; Tue, 15 Nov 2022 00:33:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E489A3858C60 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668472432; 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: in-reply-to:in-reply-to:references:references; bh=YewhL0RKRBMrEE76GbwjrdXhFvWNaK/9t87KdWxO87k=; b=DyyV8bToXYm7zrATIEHtbijrrdQ5hzcMLmcFzIl51AC6xRH9l1C1So3OO6r2uwfs7nzZEe 16oxZ8dbPKVfE1QSTGNIDtqxDogWqeMJ0aVGiM42X7y5X7Dq9vwU7AkWp3ReDeetg3aOQT tHkdUfHtZc2GSRYIwMW4C+jxwE2AcTA= 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-Google-Smtp-Source: AA0mqf4ib1NriAM5J3lq5t4Vxelx5dzDCJeDRnOphNDKf5v6Px3hUC74H4SPobSXpK/SMu7pftzzvQ== 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 From: Marek Polacek 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-Type: text/plain; charset=us-ascii 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 List-Id: 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 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" } base-commit: c41bbfcaf9d6ef5b57a7e89bba70b861c08a686b -- 2.38.1