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 DE577393BA7B for ; Tue, 15 Nov 2022 22:10:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DE577393BA7B 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=1668550247; 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=S/svJcgwx65LxPuQR8bKuOFJAZ5iWYpoyEdHVmEGkfY=; b=GT5aGA2CqS7ZdyBbCenacdcd+sWLX4gZlQ2eixia7HcZiz05PihUH37Ywct5/wqhTZCLiM R3KXhq+XSj8l9bui6jhReLVEl9UUCKEpOWv94PwFzGMdawwHkZAxJM8nZKdZ3sUBbWuube y6942VIQ7JLXXGoESEkWNAv/jq2NnU8= 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-527-VE8jDLAMN72h0weQ8yO2-w-1; Tue, 15 Nov 2022 17:10:46 -0500 X-MC-Unique: VE8jDLAMN72h0weQ8yO2-w-1 Received: by mail-qt1-f200.google.com with SMTP id c19-20020a05622a059300b003a51d69906eso11314692qtb.1 for ; Tue, 15 Nov 2022 14:10:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=S/svJcgwx65LxPuQR8bKuOFJAZ5iWYpoyEdHVmEGkfY=; b=Mj9PXUG7kZUhZYdMCj/jKH0vUM3uAdHbGBgWxrrlu7fmA8PubkeTKpY0FpxRxp6m/c qWE4thrFrur5swKwTanh0kSgwPzQ60SNp2+ZTkndzLdblkO8SVBIngaRHNeqH5WQ9l7h A4Os2uYe9ZEhuVT//628ZPjMOuvNRVaJBH1ziqApjg6qLbdwbSxPX1HAP3wFZXdcOIaC w1xavVVGZKER+aLIq6yaEFT7kKmJPJr6HqvVKwY3exanDvDTHgMOqjmvHVMSDDuJUU4v QnRQkKQwOyouxHm29SaVgmWe0QRmvo+7c/e/zZWm5jxzcZJmOxJjNNakBl0SZJq77oHx Pq6Q== X-Gm-Message-State: ANoB5pnXY1/njOoph0dhtup2ecI/7tcdbuuokT2H7ojfxaYSEPHTN2w8 FnAESQrHjtUIkmViQFlG8k2fGIiwG1eGk0c4qzLhYRIXuUyX+W5qy80ri+3yR8R6VPr2WyogKSJ YO337t3W79ecmc3TqTg== X-Received: by 2002:a05:622a:4c07:b0:3a5:26b9:d4b1 with SMTP id ey7-20020a05622a4c0700b003a526b9d4b1mr18325505qtb.413.1668550245493; Tue, 15 Nov 2022 14:10:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf6iGuurW3rOEC8skQBVytpASYuXu+QuyMc1KClamHxK4KMTcEUaoC8vOmM5gvrA3lH3YfNJZA== X-Received: by 2002:a05:622a:4c07:b0:3a5:26b9:d4b1 with SMTP id ey7-20020a05622a4c0700b003a526b9d4b1mr18325484qtb.413.1668550245157; Tue, 15 Nov 2022 14:10:45 -0800 (PST) Received: from [192.168.1.101] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id y14-20020a05620a44ce00b006fb7c42e73asm4482403qkp.21.2022.11.15.14.10.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Nov 2022 14:10:44 -0800 (PST) Message-ID: Date: Tue, 15 Nov 2022 17:10:43 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH v2] c++: Disable -Wignored-qualifiers for template args [PR107492] To: Marek Polacek Cc: GCC Patches References: <20221101170156.52672-1-polacek@redhat.com> <8278b3b0-6af7-8c1a-0aad-a093419d7672@redhat.com> From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,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 11/14/22 14:33, Marek Polacek wrote: > 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. Well, technically they matter in all contexts, including function declaration: const void f(); template struct same; template struct same{}; same s; but much more likely to be a confused user in that case, whereas in a template context it's likely to be some deep magic. :) > Updated patch below, plus I've extended the testcase. Thanks, > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? OK. > -- >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