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.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 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=1664222058; 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=AqKmNQns6lTDHCLfSOQRfLbO3dOkveF4xSXkEOPDZ3A=; b=SDANkW32IRGtFX5YcPFC4QLqu7cNpM8IHMWvUM/1p8ea4wMIqJIc9IW3FDn7VRi4a9oGMM yD74L1ZFPTpZBipRqYpvcEe51/uwFtBh4zemhYQAlPkxW1mEiOsneWFhW2F4YP9c2b2PIv 9PwbkpKoSV9OPnAVEM1WJz4CVCgfxBU= 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-Google-Smtp-Source: AMsMyM4jsQpNTA4orThScF7Pih8KyO4jSvv3FEw1MUxlWz0i/adcLuSKjzojg732lo57+A+4PF2IyA== 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 From: Marek Polacek To: Jason Merrill Cc: Richard Biener , GCC Patches 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-Type: text/plain; charset=us-ascii 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 List-Id: 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(-) 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