[PATCH] D95396: Improve static_assert/_Static_assert diagnostics

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 19 10:18:44 PST 2021


aaron.ballman added inline comments.


================
Comment at: clang/lib/Lex/PPDirectives.cpp:2884
+    Tok.setKind(tok::kw__Static_assert);
+    Tok.setIdentifierInfo(getIdentifierInfo("_Static_assert"));
+    MI->AddTokenToBody(Tok);
----------------
rsmith wrote:
> Do we need to give the expansion token a source location? What do diagnostics pointing at this token look like?
Given:
```
#define assert

// This is a comment
int i = 0;
static_assert(0, "test");
```
I get:
```
F:\llvm-project>llvm\out\build\x64-Debug\bin\clang.exe -fsyntax-only "F:\Aaron B
allman\Desktop\test.c"
F:\Aaron Ballman\Desktop\test.c:5:1: error: static_assert failed "test"
static_assert(0, "test");
^             ~
F:\Aaron Ballman\Desktop\test.c:5:1: note: expanded from macro 'static_assert'
static_assert(0, "test");
^
1 error generated.
```
which is a bit funky due to the note. However, I'm not certain what source location to give it. If I give it the location of the `assert` identifier, then I get output like:
```
F:\llvm-project>llvm\out\build\x64-Debug\bin\clang.exe -fsyntax-only "F:\Aaron B
allman\Desktop\test.c"
F:\Aaron Ballman\Desktop\test.c:5:1: error: static_assert failed "test"
static_assert(0, "test");
^             ~
F:\Aaron Ballman\Desktop\test.c:1:9: note: expanded from macro 'static_assert'
#define assert
        ^
1 error generated.
```
which seems even more mysterious.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95396/new/

https://reviews.llvm.org/D95396



More information about the cfe-commits mailing list