Issue 138100
Summary [clang] `clang diagnostic` breaks `_Pragma`
Labels clang
Assignees
Reporter Eisenwave
    https://godbolt.org/z/bsjasnK8T
```cpp
#define DO_PRAGMA_(...) _Pragma(#__VA_ARGS__)
#define DO_PRAGMA(...) DO_PRAGMA_(__VA_ARGS__)

#define DIAGNOSTIC_IGNORED(...) DO_PRAGMA(clang diagnostic ignored __VA_ARGS__)

DIAGNOSTIC_IGNORED(-Wdeprecated)
```
This doesn't work and produces the error:
```
clang++: warning: argument unused during compilation: '-S' [-Wunused-command-line-argument]
<source>:6:1: error: expected string literal in pragma diagnostic
    6 | DIAGNOSTIC_IGNORED(-Wdeprecated)
      | ^
<source>:4:33: note: expanded from macro 'DIAGNOSTIC_IGNORED'
    4 | #define DIAGNOSTIC_IGNORED(...) DO_PRAGMA(clang diagnostic ignored __VA_ARGS__)
      | ^
<source>:2:24: note: expanded from macro 'DO_PRAGMA'
    2 | #define DO_PRAGMA(...) DO_PRAGMA_(__VA_ARGS__)
      | ^
<source>:1:25: note: expanded from macro 'DO_PRAGMA_'
    1 | #define DO_PRAGMA_(...) _Pragma(#__VA_ARGS__)
      | ^
<scratch space>:5:27: note: expanded from here
    5 |  clang diagnostic ignored -Wdeprecated
      |
```
If we instead write
```cpp
#define DIAGNOSTIC_IGNORED(...) DO_PRAGMA(lmao __VA_ARGS__)
```
The code is preprocessed as expected, and the `-E` output is:
```cpp
#pragma lmao -Wdeprecated
```
Such uses of `_Pragma` ough to be valid.

The error is specific to `clang diagnostic` inside `_Pragma`. If we write `clang dogs` instead, it works.

GCC accepts this code (with `GCC diagnostic` of course).
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to