c++: warn about using keywords as identifiers [PR106111]
commit2ea6c59349793761b9c00f75ef281ac413566b2f
authorMarek Polacek <polacek@redhat.com>
Tue, 28 Jun 2022 22:59:19 +0000 (28 18:59 -0400)
committerMarek Polacek <polacek@redhat.com>
Fri, 1 Jul 2022 15:09:38 +0000 (1 11:09 -0400)
tree670742470e7c107fe1eb53eb3d520ca06cd1a389
parent9234cdca6ee88badfc00297e72f13dac4e540c79
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.
gcc/c-family/c-common.h
gcc/cp/parser.cc
gcc/testsuite/g++.dg/cpp0x/keywords1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/keywords1.C [new file with mode: 0644]