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

Ken Matsui via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 10 08:21:36 PDT 2022


ken-matsui added a comment.

In D125178#3503617 <https://reviews.llvm.org/D125178#3503617>, @aaron.ballman wrote:

> It looks like precommit CI caught some related failures:
>
>   Failed Tests (7):
>     Clang :: Lexer/deprecate-macro.c
>     Clang :: Lexer/unsafe-macro.c
>     Clang :: Preprocessor/elifdef.c
>     Clang :: Preprocessor/if_warning.c
>     Clang :: Preprocessor/ifdef-recover.c
>     Clang :: Preprocessor/macro_misc.c
>     Clang :: Preprocessor/macro_vaopt_check.cpp

Ahhh, my bad. Thank you for your heads up!



================
Comment at: clang/include/clang/Basic/DiagnosticLexKinds.td:696-698
+def ext_c2x_pp_directive : Extension<
+  "%select{#elifdef|#elifndef}0 is a C2x extension">,
+  InGroup<CPre2xCompatPedantic>;
----------------
aaron.ballman wrote:
> ken-matsui wrote:
> > aaron.ballman wrote:
> > > I think we need two diagnostics, one for C2x and one for C++2b (https://wg21.link/p2334 was adopted for C++23). Each of these diagnostics should come in a pair:
> > > ```
> > > def warn_cxx20_compat_pp_directive : Warning<
> > >   "use of a '#%select{elifdef|elifndef}0' directive is incompatible with C++ standards before C++2b",
> > >   InGroup<CXXPre2bCompat>, DefaultIgnore;
> > > def ext_cxx20_pp_directive : ExtWarn<
> > >   "use of a '#%select{elifdef|elifndef}0' directive is a C++2b extension",
> > >   InGroup<CXX2b>;
> > > ```
> > > and similar for C, except with wording about C standards and in the C warning groups.
> > I thought I had to use `Extension` here, but what is the difference between `Warning`, `ExtWarn`, and `Extension`?
> Great question!
> 
> `Extension` diagnostics are warnings that are enabled via `-pedantic` but otherwise off by default.
> `ExtWarn` diagnostics are warnings that are enabled via `-pedantic` but are also on by default.
> `Warning` diagnostics are warnings. You can use things like `DefaultIgnore` or `DefaultError` to control the default behavior of the warning.
> `Error` diagnostics are errors.
> 
> You'll typically use `Extension` or `ExtWarn` for things that are extensions of some sort, but which one you use depends on how important the warning is. We've traditionally handled "use of whatever is a C++NN extension" warnings as `ExtWarn` whereas the "use of whatever is incompatible with C++ standards before C++NN" warnings are usually `Extension`.
In this case, `compat_pp_directive` for C++2b & C2x uses `Warning`, but why did you choose it rather than `Extension`?


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