[PATCH] D129048: Rewording the "static_assert" to static assertion

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 2 04:58:20 PDT 2022

aaron.ballman added a comment.

In D129048#3692394 <https://reviews.llvm.org/D129048#3692394>, @thakis wrote:

> This change caused a ton of churn, for what I understand fix the diag in C mode when assert.h is not included.

Which is not that uncommon of a scenario: https://sourcegraph.com/search?q=context:global+file:.*%5C.c+_Static_assert&patternType=literal&case=yes

> IMHO, it would've been better to change the diag to say either `static_assert` as before in c++ mode or when assert.h is included (i.e. almost always), and `_Static_assert` else. You can use PP.getLastMacroWithSpelling() to (effectively) detect if assert.h was included.
> Is this something y'all had considered?

Yes, and that approach is actually more complicated to get correct. Part of the trouble is MSVC compatibility where `static_assert` is allowed in C mode even without including `assert.h` and that kind of thing. Ultimately, we decided the principle is: if the diagnostic is about parsing the syntax we'll use the actual token name, otherwise we'll use "static assertion" as a prose term instead to avoid having the diagnostic be wrong in edge cases.

  rG LLVM Github Monorepo



More information about the cfe-commits mailing list