diff options
author | Marek Polacek <polacek@redhat.com> | 2022-06-28 18:59:19 -0400 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2022-07-01 11:09:38 -0400 |
commit | 2ea6c59349793761b9c00f75ef281ac413566b2f (patch) | |
tree | 670742470e7c107fe1eb53eb3d520ca06cd1a389 /gcc/cp | |
parent | 9234cdca6ee88badfc00297e72f13dac4e540c79 (diff) | |
download | gcc-2ea6c59349793761b9c00f75ef281ac413566b2f.zip gcc-2ea6c59349793761b9c00f75ef281ac413566b2f.tar.gz gcc-2ea6c59349793761b9c00f75ef281ac413566b2f.tar.bz2 |
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.
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/parser.cc | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index f6bc8db..c5d1f9d 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -890,10 +890,14 @@ cp_lexer_get_preprocessor_token (unsigned flags, cp_token *token) else { if (warn_cxx11_compat - && C_RID_CODE (token->u.value) >= RID_FIRST_CXX11 - && C_RID_CODE (token->u.value) <= RID_LAST_CXX11) + && ((C_RID_CODE (token->u.value) >= RID_FIRST_CXX11 + && C_RID_CODE (token->u.value) <= RID_LAST_CXX11) + /* These are outside the CXX11 range. */ + || C_RID_CODE (token->u.value) == RID_ALIGNOF + || C_RID_CODE (token->u.value) == RID_ALIGNAS + || C_RID_CODE (token->u.value)== RID_THREAD)) { - /* Warn about the C++0x keyword (but still treat it as + /* Warn about the C++11 keyword (but still treat it as an identifier). */ warning_at (token->location, OPT_Wc__11_compat, "identifier %qE is a keyword in C++11", |