[PATCH] D125178: Warn if using `elifdef` & `elifndef` in not C2x & C++2b mode

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 11 04:48:05 PDT 2022


aaron.ballman added inline comments.


================
Comment at: clang/include/clang/Basic/DiagnosticLexKinds.td:698
+def warn_c2x_compat_pp_directive : Warning<
+  "use of a '#%select{elifdef|elifndef}0' directive is incompatible with C standards before C2x">,
+  InGroup<CPre2xCompat>, DefaultIgnore;
----------------
(You may also need to rewrap to 80 col limits.)

And do the same for the other three, so that you can use `PPElifDiag` for it.


================
Comment at: clang/lib/Lex/PPDirectives.cpp:663
+
+        Diag(Tok, DiagID) << (IsElifDef ? PED_Elifdef : PED_Elifndef) - 1;
+
----------------
I like the way you're thinking about this, but I don't like how clever the code is. I'd rather update the comment on `PPElifDiag` to mention `warn_*_compat_pp_directive` and `ext_*_pp_directive`, and then update those diagnostics to have a bogus select slot for the `PED_Elif` that will never be used.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125178



More information about the cfe-commits mailing list