[v2] c++: Don't quote nothrow in diagnostic
Checks
Commit Message
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
> > <gcc-patches@gcc.gnu.org> wrote:
> > >
> > > In <https://gcc.gnu.org/pipermail/gcc-patches/2022-September/602057.html>
> > > 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 <https://gcc.gnu.org/pipermail/gcc-patches/2022-September/602057.html>
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
Comments
On Mon, Sep 26, 2022 at 9:54 PM Marek Polacek <polacek@redhat.com> 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
> > > <gcc-patches@gcc.gnu.org> wrote:
> > > >
> > > > In <https://gcc.gnu.org/pipermail/gcc-patches/2022-September/602057.html>
> > > > 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 <https://gcc.gnu.org/pipermail/gcc-patches/2022-September/602057.html>
> 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 %<nothrow%> copy assignable", t1);
> + inform (loc, " %qT is not nothrow copy assignable", t1);
> break;
> case CPTK_HAS_NOTHROW_CONSTRUCTOR:
> - inform (loc, " %qT is not %<nothrow%> default constructible", t1);
> + inform (loc, " %qT is not nothrow default constructible", t1);
> break;
> case CPTK_HAS_NOTHROW_COPY:
> - inform (loc, " %qT is not %<nothrow%> 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 %<nothrow%> 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 %<nothrow%> default constructible", t1);
> + inform (loc, " %qT is not nothrow default constructible", t1);
> else
> - inform (loc, " %qT is not %<nothrow%> 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 %<nothrow%> 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<class T, class U>
> 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<class T, class... Args>
> concept Constructible = __is_constructible(T, Args...);
> @@ -37,9 +37,9 @@ concept TriviallyConstructible = __is_trivially_constructible(T, Args...);
>
> template<class T, class... Args>
> 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<class T>
> concept UniqueObjReps = __has_unique_object_representations(T);
>
> base-commit: 7701ea4a70a5a5c0fd977da90a30ffc4f3f87617
> --
> 2.37.3
>
On Tue, Sep 27, 2022 at 10:41:29AM +0200, Richard Biener wrote:
> On Mon, Sep 26, 2022 at 9:54 PM Marek Polacek <polacek@redhat.com> 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
> > > > <gcc-patches@gcc.gnu.org> wrote:
> > > > >
> > > > > In <https://gcc.gnu.org/pipermail/gcc-patches/2022-September/602057.html>
> > > > > 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?
I don't really see that. [meta.unary.prop] says "known not to throw any
exceptions" for the _nothrow built-ins. That may be too long to use in
diagnostics. And the warning would probably complain about the unquoted
'throw' in it. :)
> > 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.
Marek
On 9/27/22 04:41, Richard Biener wrote:
> On Mon, Sep 26, 2022 at 9:54 PM Marek Polacek <polacek@redhat.com> 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
>>>> <gcc-patches@gcc.gnu.org> wrote:
>>>>>
>>>>> In <https://gcc.gnu.org/pipermail/gcc-patches/2022-September/602057.html>
>>>>> 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?
Not in the language, only in library names like
std::is_nothrow_constructible.
Jason
@@ -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"),
@@ -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 %<nothrow%> copy assignable", t1);
+ inform (loc, " %qT is not nothrow copy assignable", t1);
break;
case CPTK_HAS_NOTHROW_CONSTRUCTOR:
- inform (loc, " %qT is not %<nothrow%> default constructible", t1);
+ inform (loc, " %qT is not nothrow default constructible", t1);
break;
case CPTK_HAS_NOTHROW_COPY:
- inform (loc, " %qT is not %<nothrow%> 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 %<nothrow%> 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 %<nothrow%> default constructible", t1);
+ inform (loc, " %qT is not nothrow default constructible", t1);
else
- inform (loc, " %qT is not %<nothrow%> 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 %<nothrow%> 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 "
@@ -21,7 +21,7 @@ concept TriviallyAssignable = __is_trivially_assignable(T, U);
template<class T, class U>
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<class T, class... Args>
concept Constructible = __is_constructible(T, Args...);
@@ -37,9 +37,9 @@ concept TriviallyConstructible = __is_trivially_constructible(T, Args...);
template<class T, class... Args>
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<class T>
concept UniqueObjReps = __has_unique_object_representations(T);