[clang] [clang] Add test for CWG3088 about macros defining special identifiers (PR #189309)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 30 05:43:53 PDT 2026


================
@@ -0,0 +1,270 @@
+// RUN: %clang_cc1 -std=c++98 -fexceptions -fcxx-exceptions -pedantic-errors %s -verify-directives -verify=expected
+// RUN: %clang_cc1 -std=c++11 -fexceptions -fcxx-exceptions -pedantic-errors %s -verify-directives -verify=expected,since-cxx11
+// RUN: %clang_cc1 -std=c++14 -fexceptions -fcxx-exceptions -pedantic-errors %s -verify-directives -verify=expected,since-cxx11
+// RUN: %clang_cc1 -std=c++17 -fexceptions -fcxx-exceptions -pedantic-errors %s -verify-directives -verify=expected,since-cxx11
+// RUN: %clang_cc1 -std=c++20 -fexceptions -fcxx-exceptions -pedantic-errors %s -verify-directives -verify=expected,since-cxx11,since-cxx20
+// RUN: %clang_cc1 -std=c++23 -fexceptions -fcxx-exceptions -pedantic-errors %s -verify-directives -verify=expected,since-cxx11,since-cxx20
+// RUN: %clang_cc1 -std=c++2c -fexceptions -fcxx-exceptions -pedantic-errors %s -verify-directives -verify=expected,since-cxx11,since-cxx20
+
+namespace cwg3088 { // cwg3088: partial
+#define asm
+// expected-error at -1 {{keyword is hidden by macro definition}}
+#define auto
+// expected-error at -1 {{keyword is hidden by macro definition}}
+#define bool
+// expected-error at -1 {{keyword is hidden by macro definition}}
+#define break
+// expected-error at -1 {{keyword is hidden by macro definition}}
+#define case
+// expected-error at -1 {{keyword is hidden by macro definition}}
+#define catch
+// expected-error at -1 {{keyword is hidden by macro definition}}
+#define char
+// expected-error at -1 {{keyword is hidden by macro definition}}
+#define class
+// expected-error at -1 {{keyword is hidden by macro definition}}
+#define const
+// FIXME-error at -1 {{keyword is hidden by macro definition}}
----------------
AaronBallman wrote:

Fixing this will break code, it is not rare for code to have a mode that does something like `#define const` in one branch and `#define const const` in another so you can control whether `const` is applied or not via a configuration macro.

That's not to say "don't do it" but I would be opposed to fixing it as a DR. In general, when a committee decides to knowingly break existing user code, I'd rather we err on the side of making it harder for users to upgrade to that standard version than making it harder for users to upgrade Clang itself.

https://github.com/llvm/llvm-project/pull/189309


More information about the cfe-commits mailing list