From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by sourceware.org (Postfix) with ESMTPS id 0BF173852776 for ; Tue, 27 Sep 2022 08:41:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0BF173852776 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-x52a.google.com with SMTP id x21so12187732edd.11 for ; Tue, 27 Sep 2022 01:41:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=7YQev7ag1lxAyuULl4JcN8DhLtE/IT9OzgHQAbbib98=; b=JBepLI7Cs20zZEZ+Tsyyf+NLYeZm5PKC8USTEs8crBmG9YZ3LwaVWRx1drteK/B4B7 oTWo/iGlN2EN2LQwm/7DtGrvBBKo3ER0pAnIyv3Bt8jNxH0Whr5iRKUp2DbvkjvKK3Ei GUx6UKI2cEAGm8ztlb5Q8S9bUjufz5I301T5R4rfwo4DYVe7kPYm4/N5CO5kN7vvOE5N IJA29l7qgCR+aYO4B2pN46lFuziTVHOyKqCiS5wdDLacpYFYVU+x8D4gGRty6YofdP7p U13Eucrmcl90ZVdUJewieDJAJN2HXipGbrRcSSbDBU3DdngorrG3JarMLuB7URafTBVM VzQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=7YQev7ag1lxAyuULl4JcN8DhLtE/IT9OzgHQAbbib98=; b=t6U7lUEyicgF0vdoTo7gnJjcb17cUgF6P4QGbq8BUJcMeqPvBFHqbUdAhOUjIkyjqn VFXEpetrwHWuarrGN4R4qQCi04WfNzcXO9CXVrq8iAmqtJ4D3eOXm3wlvbiyIVmXJ+X0 BF8eQU3TBPYeR1xoz5lNZFFNhOYHh3w8y/pZRUpOMplxxDmJOpAW/TTzceT6nFsa4aQ7 myXEGWdr925ELZ+aONh7SI7Bak6Lly547zuwYbMQHNnFkaoPpwDjabpm+jIe6NRgmqn8 7QARFI9U8jxbzAwqtIA4YjM24zZP4vih/B4NsJT4IJkzlwjVunD0Kd+MMndIsFp0XDxb xoFg== X-Gm-Message-State: ACrzQf1D+M5FsMYa7Y58wymRD0mpGK4O4vFVUkeHDn93zCq2vOv/AyHV s9wOCkBrRC1Jj7p5gd9yRxKeGb6spbV+oSP4pxaArDkcgI4= X-Google-Smtp-Source: AMsMyM4XiTUEfbakhn1Ml4LXErwMi4/6DmQvakkw3N/o7XuPLBE4hi08B9YP/wqHQIkcZyNdUPPPPNKTFJKQyhzis7g= X-Received: by 2002:a05:6402:3786:b0:451:24da:f8c9 with SMTP id et6-20020a056402378600b0045124daf8c9mr26598275edb.250.1664268101765; Tue, 27 Sep 2022 01:41:41 -0700 (PDT) MIME-Version: 1.0 References: <20220923184026.379494-1-polacek@redhat.com> <5b9a9ee4-f6ed-14d3-b069-e3222739f8d2@redhat.com> In-Reply-To: From: Richard Biener Date: Tue, 27 Sep 2022 10:41:29 +0200 Message-ID: Subject: Re: [PATCH v2] c++: Don't quote nothrow in diagnostic To: Marek Polacek Cc: Jason Merrill , GCC Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 Mon, Sep 26, 2022 at 9:54 PM Marek Polacek wrote: > > 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. Yes. I assume that terms like "nothrow constructible" are used in the C++ standard? > 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? Sure. Thanks, Richard. > -- >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(-) > > 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); > > base-commit: 7701ea4a70a5a5c0fd977da90a30ffc4f3f87617 > -- > 2.37.3 >