[Bug c++/106111] -Wc++20-compat doesn't warn about using `requires` as an identifier
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Jun 28 09:53:25 GMT 2022
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.
More information about the Gcc-bugs
mailing list