From patchwork Mon Sep 26 19:54:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1474 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp1663799wrt; Mon, 26 Sep 2022 12:55:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7DXFrd5k+qwQIjQJzEC6Kfh93pEBaSoUXHeDzaIrguWa+yyKu3xkCbxuMMmev+R7m3WypD X-Received: by 2002:a05:6402:440f:b0:435:2e63:aca9 with SMTP id y15-20020a056402440f00b004352e63aca9mr23757455eda.162.1664222103986; Mon, 26 Sep 2022 12:55:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664222103; cv=none; d=google.com; s=arc-20160816; b=lQOhrOTCXmSXUM9cMrY++YWf1rR5kU/8Lfmx5uET/i9g8CvaOa4k0Z55y1lwBYnQG3 zdXOw9zQXVqY4g/uJWzJ/49BHBmHr8Q7nliW2XpDX5kWBPmg6KXZ22BC5SSEy9Jqa0kN ULr3LCXF9BauluPEG5N0NTFsvmgKDiwh6ZRUVY+CO/7AuqIcnLSdIxgKX7xVftJrr5bc OaU3QE4MWAZ++n003wW5itPd1hu7Bsjq/X+Uenqwt5AUBT5r/empc5hEnH0rJzOqpPYk P98jblhJ9oUh6lNmTwKNSlhwNokolRdDjLhEcHirjWy223InLT5gOhgRyY9Y+QETR3Q1 GnLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:date:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=AqKmNQns6lTDHCLfSOQRfLbO3dOkveF4xSXkEOPDZ3A=; b=OlGNSqnUBP3meV82sbRl6AcvRW33BXLZSORaGjUus9zfwxi++5xnR2SDjdmHV4kYan eg3vwDt80AeeuXIXDJCcU/OV3qwB8KaA2DkrMKQI30ZlN1DVoHZ+pnkHwBKB9fqCwzej 3YGJWGW4pXsQ86dSiEiVvBEb0juuAdi2ztyPkcFXl1tC9mW9vYozKk7WbV2AIFPprRNp TX05C3KTPkLt1C92/1itoH2wRbBP4vmpiatJeJdN1emyPRCWaoDs/ZOH9RjAMkjwW62G UlN6A1clgciZjSQXX4JqF4IMKCQMT+38GJpsOQrEB9xBV04+tW4ol12t+ACPFM0IafiY uKtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ZKKiockX; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id s7-20020a50ab07000000b00446dc8f5e44si16949669edc.243.2022.09.26.12.55.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 12:55:03 -0700 (PDT) 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=ZKKiockX; 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 009CA3858D37 for ; Mon, 26 Sep 2022 19:55:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 009CA3858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664222103; bh=AqKmNQns6lTDHCLfSOQRfLbO3dOkveF4xSXkEOPDZ3A=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=ZKKiockXM7sR20X5TI4G/R6WVnq8lSOozfJnqug6kB5FZEekpt8OLev9HgKlprxtc AODr7/7mIGcPX3zNBvXSf4UMpNJZJ+I96I8CV+mKYKebzyiHcIKxTLHuojx4e+Cetx T6OPmb91evfmc45Sey2ZuakqvYSgwsA/LPp7EDKQ= 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 B66313858D37 for ; Mon, 26 Sep 2022 19:54:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B66313858D37 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-114-myLVeRXnOEuf14KBvRYsIw-1; Mon, 26 Sep 2022 15:54:17 -0400 X-MC-Unique: myLVeRXnOEuf14KBvRYsIw-1 Received: by mail-qv1-f70.google.com with SMTP id nn9-20020a056214358900b004ac7136c9a3so4458197qvb.16 for ; Mon, 26 Sep 2022 12:54:17 -0700 (PDT) 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; bh=AqKmNQns6lTDHCLfSOQRfLbO3dOkveF4xSXkEOPDZ3A=; b=UOTaIUMI6v5Pd1ibyUfnUrfK6R50EUYy4JeZWPSh5OQ9VQ3qkBeZstEWeU1iHoq5+l apPcv54TEc8hy9dIQ/Aid+qTegEIk/8RHP9WYy6/MKj2/f9JPKwhdEUpdoRZrGrhXMXs k4ejTYDSHiE16fhq3uZruDDT6D07SUbofHlhkZSSCqj2bml/DkyQ3Xb1P8t1Pb5ydJ/V SIYN9Ejaw/6BCWF7f5KNIo5Mp3OnVq9jshzAAQNLNI9CwqEt97n2l6tPIDU/j4vCDPrB T542wrK5D5tjsgm+E++nmZcxWTRldKweR3QZ8gohJmCWv81Twei2eJ21+7kP+HPanohf FlTQ== X-Gm-Message-State: ACrzQf1w8U2k/4PSgfFFdHrCSeNvIYn5NnFmhl8sLdIK3ryVQnfw5n+R aJOHJ62YaHogKy+A4WbQuIj1+vqEmTUoI3rVDxNeKDWAoHwkqvOBTRx2OHnhUX7+2Rjyu7qu6q2 +NCPJf0jPjP5O8Y7Kqg== X-Received: by 2002:a05:622a:4204:b0:35c:ddac:9896 with SMTP id cp4-20020a05622a420400b0035cddac9896mr19998459qtb.478.1664222055649; Mon, 26 Sep 2022 12:54:15 -0700 (PDT) X-Received: by 2002:a05:622a:4204:b0:35c:ddac:9896 with SMTP id cp4-20020a05622a420400b0035cddac9896mr19998432qtb.478.1664222055364; Mon, 26 Sep 2022 12:54:15 -0700 (PDT) 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 j10-20020a05620a288a00b006ce9e880c6fsm12362159qkp.111.2022.09.26.12.54.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 12:54:14 -0700 (PDT) Date: Mon, 26 Sep 2022 15:54:13 -0400 To: Jason Merrill Subject: [PATCH v2] c++: Don't quote nothrow in diagnostic Message-ID: References: <20220923184026.379494-1-polacek@redhat.com> <5b9a9ee4-f6ed-14d3-b069-e3222739f8d2@redhat.com> MIME-Version: 1.0 In-Reply-To: <5b9a9ee4-f6ed-14d3-b069-e3222739f8d2@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=-11.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FILL_THIS_FORM, FILL_THIS_FORM_LONG, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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 Cc: GCC Patches 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?1744786929174059143?= X-GMAIL-MSGID: =?utf-8?q?1745063356930224737?= On Mon, Sep 26, 2022 at 12:34:04PM -0400, Jason Merrill wrote: > On 9/26/22 03:50, Richard Biener wrote: > > On Fri, Sep 23, 2022 at 8:41 PM Marek Polacek via Gcc-patches > > wrote: > > > > > > In > > > Jason noticed that we quote "nothrow" in diagnostics even though it's > > > not a keyword in C++. Just removing the quotes didn't work because > > > then -Wformat-diag complains, so this patch replaces it with "no-throw". > > > > > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? > > > > That doesn't look like an improvement to me. Can we quote 'nothrow()' instead? Understood. > nothrow() is a syntax error; the C++11 keyword is 'noexcept'. std::nothrow > is a dummy placement argument used to indicate that a new-expression should > return null rather than throw on failure. > > But bizarrely, the library traits use the word "nothrow". Marek's patch > clarifies that we are not trying to refer to anything in the language. > > > I'd rather leave it alone than changing it to no-throw. Why does -Wformat-diag > > complain? If we shouldn't quote nothrow that should be adjusted? > > I think -Wformat-diag complains because "nothrow" is an attribute; it also > includes some other attribute names in the list of "keywords". > > I would also be fine with just removing the quotes and removing nothrow from > c_keywords. Like below? Bootstrapped/regtested on x86_64-pc-linux-gnu. Note that now I see warnings with my system compiler (gcc-12.2.1). Can I commit the c-format.cc hunk to gcc 12 so that eventually even gcc 12 stops warning? -- >8 -- In Jason noticed that we quote "nothrow" in diagnostics even though it's not a keyword in C++. This patch removes the quotes and also drops "nothrow" from c_keywords. gcc/c-family/ChangeLog: * c-format.cc (c_keywords): Drop nothrow. gcc/cp/ChangeLog: * constraint.cc (diagnose_trait_expr): Say "nothrow" without quotes rather than in quotes. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-traits3.C: Adjust expected diagnostics. --- gcc/c-family/c-format.cc | 3 +-- gcc/cp/constraint.cc | 14 +++++++------- gcc/testsuite/g++.dg/cpp2a/concepts-traits3.C | 8 ++++---- 3 files changed, 12 insertions(+), 13 deletions(-) base-commit: 7701ea4a70a5a5c0fd977da90a30ffc4f3f87617 diff --git a/gcc/c-family/c-format.cc b/gcc/c-family/c-format.cc index a6c380bf1c8..a2026591ed1 100644 --- a/gcc/c-family/c-format.cc +++ b/gcc/c-family/c-format.cc @@ -2900,7 +2900,7 @@ static const token_t cxx_opers[] = }; /* Common C/C++ keywords that are expected to be quoted within the format - string. Keywords like auto, inline, or volatile are exccluded because + string. Keywords like auto, inline, or volatile are excluded because they are sometimes used in common terms like /auto variables/, /inline function/, or /volatile access/ where they should not be quoted. */ @@ -2927,7 +2927,6 @@ static const token_t c_keywords[] = NAME ("noinline", NULL), NAME ("nonnull", NULL), NAME ("noreturn", NULL), - NAME ("nothrow", NULL), NAME ("offsetof", NULL), NAME ("readonly", "read-only"), NAME ("readwrite", "read-write"), diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 5839bfb4b52..266ec581a20 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3592,13 +3592,13 @@ diagnose_trait_expr (tree expr, tree args) switch (TRAIT_EXPR_KIND (expr)) { case CPTK_HAS_NOTHROW_ASSIGN: - inform (loc, " %qT is not % copy assignable", t1); + inform (loc, " %qT is not nothrow copy assignable", t1); break; case CPTK_HAS_NOTHROW_CONSTRUCTOR: - inform (loc, " %qT is not % default constructible", t1); + inform (loc, " %qT is not nothrow default constructible", t1); break; case CPTK_HAS_NOTHROW_COPY: - inform (loc, " %qT is not % copy constructible", t1); + inform (loc, " %qT is not nothrow copy constructible", t1); break; case CPTK_HAS_TRIVIAL_ASSIGN: inform (loc, " %qT is not trivially copy assignable", t1); @@ -3674,7 +3674,7 @@ diagnose_trait_expr (tree expr, tree args) inform (loc, " %qT is not trivially assignable from %qT", t1, t2); break; case CPTK_IS_NOTHROW_ASSIGNABLE: - inform (loc, " %qT is not % assignable from %qT", t1, t2); + inform (loc, " %qT is not nothrow assignable from %qT", t1, t2); break; case CPTK_IS_CONSTRUCTIBLE: if (!t2) @@ -3690,9 +3690,9 @@ diagnose_trait_expr (tree expr, tree args) break; case CPTK_IS_NOTHROW_CONSTRUCTIBLE: if (!t2) - inform (loc, " %qT is not % default constructible", t1); + inform (loc, " %qT is not nothrow default constructible", t1); else - inform (loc, " %qT is not % constructible from %qE", t1, t2); + inform (loc, " %qT is not nothrow constructible from %qE", t1, t2); break; case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS: inform (loc, " %qT does not have unique object representations", t1); @@ -3701,7 +3701,7 @@ diagnose_trait_expr (tree expr, tree args) inform (loc, " %qT is not convertible from %qE", t2, t1); break; case CPTK_IS_NOTHROW_CONVERTIBLE: - inform (loc, " %qT is not % convertible from %qE", t2, t1); + inform (loc, " %qT is not nothrow convertible from %qE", t2, t1); break; case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: inform (loc, " %qT is not a reference that binds to a temporary " diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-traits3.C b/gcc/testsuite/g++.dg/cpp2a/concepts-traits3.C index f20608b6918..3e87da4611e 100644 --- a/gcc/testsuite/g++.dg/cpp2a/concepts-traits3.C +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-traits3.C @@ -21,7 +21,7 @@ concept TriviallyAssignable = __is_trivially_assignable(T, U); template concept NothrowAssignable = __is_nothrow_assignable(T, U); -// { dg-message "'S' is not 'nothrow' assignable from 'int'" "" { target *-*-* } .-1 } +// { dg-message "'S' is not nothrow assignable from 'int'" "" { target *-*-* } .-1 } template concept Constructible = __is_constructible(T, Args...); @@ -37,9 +37,9 @@ concept TriviallyConstructible = __is_trivially_constructible(T, Args...); template concept NothrowConstructible = __is_nothrow_constructible(T, Args...); -// { dg-message "'S' is not 'nothrow' default constructible" "" { target *-*-* } .-1 } -// { dg-message "'S' is not 'nothrow' constructible from 'int'" "" { target *-*-* } .-2 } -// { dg-message "'S' is not 'nothrow' constructible from 'int, char'" "" { target *-*-* } .-3 } +// { dg-message "'S' is not nothrow default constructible" "" { target *-*-* } .-1 } +// { dg-message "'S' is not nothrow constructible from 'int'" "" { target *-*-* } .-2 } +// { dg-message "'S' is not nothrow constructible from 'int, char'" "" { target *-*-* } .-3 } template concept UniqueObjReps = __has_unique_object_representations(T);