[clang] [Clang] disallow # operators in attribute argument lists (PR #147308)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 8 04:12:43 PDT 2025


================
@@ -477,3 +477,10 @@ namespace P2361 {
 }
 
 alignas(int) struct AlignAsAttribute {}; // expected-error {{misplaced attributes; expected attributes here}}
+
+namespace GH147217 {
+  [[clang::annotate(#)]] void a();    // expected-error {{'#' is not allowed in an attribute argument list}}
----------------
AaronBallman wrote:

Can you add a test that shows we still accept this in C?

Also, can you add a test showing that the operators still work in a preprocessor context? e.g.,
```
#define ATTR_STR(X) [[clang::annotate(#X)]]
#define ATTR_PASTE(X, Y) [[clang::annotate("test", X ## Y)]]

ATTR_STR(stringify) void func1();
ATTR_PASTE(1, 2) void func2();
```
(This should probably be a `-E` test so we can validate the expected output of the preprocessor operations.)

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


More information about the cfe-commits mailing list