On 8/1/25 5:01 AM, Jakub Jelinek wrote:
On Thu, Jul 31, 2025 at 10:20:23PM +0200, Jakub Jelinek wrote:
The following patch introduces a -Wkeyword-macro warning that clang has
since 2014 to implement part of C++26 P2843R3 Preprocessing is never undefined
paper.

Here is a tiny change to the patch, added an inline function to check for
what nodes were registered for -Wkeyword-macro purposes and use that instead
of repeating the same tests in 3 spots.
The rest is unchanged.

--- gcc/cp/lex.cc.jj    2025-07-31 10:40:31.823618138 +0200
+++ gcc/cp/lex.cc       2025-07-31 14:07:27.994888827 +0200
@@ -368,6 +368,67 @@ cxx_init (void)
cxx_init_decl_processing (); + if (warn_keyword_macro)
+    {
+      for (unsigned int i = 0; i < num_c_common_reswords; ++i)
+       /* For C++ none of the keywords in [lex.key] starts with underscore,
+          don't register anything like that.  Furthermore, most of ObjC
+          keywords are context sensitive, don't complain about those
+          either.  */

Hmm, the names in "Table 4" https://eel.is/c++draft/lex.name#tab:lex.name.special are also context-sensitive. I agree with ignoring the ObjC keywords because they aren't part of the C++ standard, but I'd drop the "context-sensitive" rationale.

Otherwise the C++ parts are OK.

Jason

Reply via email to