public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/106111] New: -Wc++20-compat doesn't warn about using `requires` as an identifier
@ 2022-06-28 9:48 redi at gcc dot gnu.org
2022-06-28 9:51 ` [Bug c++/106111] " redi at gcc dot gnu.org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2022-06-28 9:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106111
Bug ID: 106111
Summary: -Wc++20-compat doesn't warn about using `requires` as
an identifier
Product: gcc
Version: unknown
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: redi at gcc dot gnu.org
Target Milestone: ---
int requires;
Clang warns about this:
r.C:1:5: warning: 'requires' is a keyword in C++20 [-Wc++20-compat]
int requires;
^
1 warning generated.
GCC should do too.
I wonder if we should warn about this by default (and suppress it if
-Wno-c++20-compat is used). A keyword that is a common English word (unlike
decltype, constexpr etc.) deserves a pretty big warning about compat with newer
standards.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/106111] -Wc++20-compat doesn't warn about using `requires` as an identifier
2022-06-28 9:48 [Bug c++/106111] New: -Wc++20-compat doesn't warn about using `requires` as an identifier redi at gcc dot gnu.org
@ 2022-06-28 9:51 ` redi at gcc dot gnu.org
2022-06-28 9:53 ` redi at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2022-06-28 9:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106111
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Looks like we don't warn about any keywords with any -Wc++NN-compat options:
int decltype, constexpr, consteval, requires, noexcept, alignof, alignas;
GCC doesn't warn about any of these, Clang only warns about two:
$ g++ -std=c++03 r.C -c -Wc++20-compat
$ clang++ -std=c++03 r.C -c -Wc++20-compat
r.C:1:26: warning: 'consteval' is a keyword in C++20 [-Wc++20-compat]
int decltype, constexpr, consteval, requires, noexcept, alignof, alignas;
^
r.C:1:37: warning: 'requires' is a keyword in C++20 [-Wc++20-compat]
int decltype, constexpr, consteval, requires, noexcept, alignof, alignas;
^
2 warnings generated.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/106111] -Wc++20-compat doesn't warn about using `requires` as an identifier
2022-06-28 9:48 [Bug c++/106111] New: -Wc++20-compat doesn't warn about using `requires` as an identifier redi at gcc dot gnu.org
2022-06-28 9:51 ` [Bug c++/106111] " redi at gcc dot gnu.org
@ 2022-06-28 9:53 ` redi at gcc dot gnu.org
2022-06-28 12:16 ` mpolacek at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2022-06-28 9:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106111
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Oh, that's because -Wc++20-compat doesn't include -Wc++17-compat etc.
With the right options GCC warns about three:
$ g++ -std=c++03 r.C -c -Wc++20-compat -Wc++11-compat -Wc++14-compat
-Wc++17-compat
r.C:1:5: warning: identifier ‘decltype’ is a keyword in C++11 [-Wc++11-compat]
1 | int decltype, constexpr, consteval, requires, noexcept, alignof,
alignas;
| ^~~~~~~~
r.C:1:15: warning: identifier ‘constexpr’ is a keyword in C++11
[-Wc++11-compat]
1 | int decltype, constexpr, consteval, requires, noexcept, alignof,
alignas;
| ^~~~~~~~~
r.C:1:47: warning: identifier ‘noexcept’ is a keyword in C++11 [-Wc++11-compat]
1 | int decltype, constexpr, consteval, requires, noexcept, alignof,
alignas;
| ^~~~~~~~
We're missing warnings for alignof and alignas in C++11, and consteval and
requires in C++20.
Clang warns about them all:
$ clang++ -std=c++03 r.C -c -Wc++20-compat -Wc++11-compat -Wc++14-compat
-Wc++17-compat
r.C:1:5: warning: 'decltype' is a keyword in C++11 [-Wc++11-compat]
int decltype, constexpr, consteval, requires, noexcept, alignof, alignas;
^
r.C:1:15: warning: 'constexpr' is a keyword in C++11 [-Wc++11-compat]
int decltype, constexpr, consteval, requires, noexcept, alignof, alignas;
^
r.C:1:26: warning: 'consteval' is a keyword in C++20 [-Wc++20-compat]
int decltype, constexpr, consteval, requires, noexcept, alignof, alignas;
^
r.C:1:37: warning: 'requires' is a keyword in C++20 [-Wc++20-compat]
int decltype, constexpr, consteval, requires, noexcept, alignof, alignas;
^
r.C:1:47: warning: 'noexcept' is a keyword in C++11 [-Wc++11-compat]
int decltype, constexpr, consteval, requires, noexcept, alignof, alignas;
^
r.C:1:57: warning: 'alignof' is a keyword in C++11 [-Wc++11-compat]
int decltype, constexpr, consteval, requires, noexcept, alignof, alignas;
^
r.C:1:66: warning: 'alignas' is a keyword in C++11 [-Wc++11-compat]
int decltype, constexpr, consteval, requires, noexcept, alignof, alignas;
^
7 warnings generated.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/106111] -Wc++20-compat doesn't warn about using `requires` as an identifier
2022-06-28 9:48 [Bug c++/106111] New: -Wc++20-compat doesn't warn about using `requires` as an identifier redi at gcc dot gnu.org
2022-06-28 9:51 ` [Bug c++/106111] " redi at gcc dot gnu.org
2022-06-28 9:53 ` redi at gcc dot gnu.org
@ 2022-06-28 12:16 ` mpolacek at gcc dot gnu.org
2022-06-28 12:20 ` mpolacek at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-06-28 12:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106111
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org
Last reconfirmed| |2022-06-28
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed, same problem with e.g.
int concept;
The problem is that cp_lexer_get_preprocessor_token has
906 if (warn_cxx20_compat
907 && C_RID_CODE (token->u.value) >= RID_FIRST_CXX20
908 && C_RID_CODE (token->u.value) <= RID_LAST_CXX20)
but requires/concept aren't in the C++20 keywords, they are marked as
D_CXX_CONCEPTS_FLAGS instead.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/106111] -Wc++20-compat doesn't warn about using `requires` as an identifier
2022-06-28 9:48 [Bug c++/106111] New: -Wc++20-compat doesn't warn about using `requires` as an identifier redi at gcc dot gnu.org
` (2 preceding siblings ...)
2022-06-28 12:16 ` mpolacek at gcc dot gnu.org
@ 2022-06-28 12:20 ` mpolacek at gcc dot gnu.org
2022-06-28 12:24 ` mpolacek at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-06-28 12:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106111
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
And for consteval the problem is likely that enum rid has:
273 RID_FIRST_CXX20 = RID_CONSTINIT,
274 RID_LAST_CXX20 = RID_CONSTINIT,
Oops.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/106111] -Wc++20-compat doesn't warn about using `requires` as an identifier
2022-06-28 9:48 [Bug c++/106111] New: -Wc++20-compat doesn't warn about using `requires` as an identifier redi at gcc dot gnu.org
` (3 preceding siblings ...)
2022-06-28 12:20 ` mpolacek at gcc dot gnu.org
@ 2022-06-28 12:24 ` mpolacek at gcc dot gnu.org
2022-07-01 15:11 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-06-28 12:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106111
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
Status|NEW |ASSIGNED
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/106111] -Wc++20-compat doesn't warn about using `requires` as an identifier
2022-06-28 9:48 [Bug c++/106111] New: -Wc++20-compat doesn't warn about using `requires` as an identifier redi at gcc dot gnu.org
` (4 preceding siblings ...)
2022-06-28 12:24 ` mpolacek at gcc dot gnu.org
@ 2022-07-01 15:11 ` cvs-commit at gcc dot gnu.org
2022-07-01 15:20 ` mpolacek at gcc dot gnu.org
2022-10-22 2:22 ` pinskia at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-07-01 15:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106111
--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:2ea6c59349793761b9c00f75ef281ac413566b2f
commit r13-1394-g2ea6c59349793761b9c00f75ef281ac413566b2f
Author: Marek Polacek <polacek@redhat.com>
Date: Tue Jun 28 18:59:19 2022 -0400
c++: warn about using keywords as identifiers [PR106111]
In C++03, -Wc++11-compat should warn about
int constexpr;
since 'constexpr' is a keyword in C++11. Jonathan reports that
we don't emit a similar warning for 'alignas' or 'alignof', and,
as I found out, 'thread_local'.
Similarly, we don't warn for most C++20 keywords. That happens
because RID_LAST_CXX20 hasn't been updated in a while.
PR c++/106111
gcc/c-family/ChangeLog:
* c-common.h (enum rid): Update RID_LAST_CXX20.
gcc/cp/ChangeLog:
* parser.cc (cp_lexer_get_preprocessor_token): Also warn about
RID_ALIGNOF, RID_ALIGNAS, RID_THREAD.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/keywords1.C: New test.
* g++.dg/cpp2a/keywords1.C: New test.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/106111] -Wc++20-compat doesn't warn about using `requires` as an identifier
2022-06-28 9:48 [Bug c++/106111] New: -Wc++20-compat doesn't warn about using `requires` as an identifier redi at gcc dot gnu.org
` (5 preceding siblings ...)
2022-07-01 15:11 ` cvs-commit at gcc dot gnu.org
@ 2022-07-01 15:20 ` mpolacek at gcc dot gnu.org
2022-10-22 2:22 ` pinskia at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-07-01 15:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106111
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed for GCC 13.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/106111] -Wc++20-compat doesn't warn about using `requires` as an identifier
2022-06-28 9:48 [Bug c++/106111] New: -Wc++20-compat doesn't warn about using `requires` as an identifier redi at gcc dot gnu.org
` (6 preceding siblings ...)
2022-07-01 15:20 ` mpolacek at gcc dot gnu.org
@ 2022-10-22 2:22 ` pinskia at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-22 2:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106111
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |13.0
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2022-10-22 2:22 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-28 9:48 [Bug c++/106111] New: -Wc++20-compat doesn't warn about using `requires` as an identifier redi at gcc dot gnu.org
2022-06-28 9:51 ` [Bug c++/106111] " redi at gcc dot gnu.org
2022-06-28 9:53 ` redi at gcc dot gnu.org
2022-06-28 12:16 ` mpolacek at gcc dot gnu.org
2022-06-28 12:20 ` mpolacek at gcc dot gnu.org
2022-06-28 12:24 ` mpolacek at gcc dot gnu.org
2022-07-01 15:11 ` cvs-commit at gcc dot gnu.org
2022-07-01 15:20 ` mpolacek at gcc dot gnu.org
2022-10-22 2:22 ` pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).