[PATCH] D130415: [Clang] Adjust extension warnings for #warning
Corentin Jabot via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Jul 23 02:10:48 PDT 2022
cor3ntin created this revision.
Herald added a project: All.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
The #warning directive is standard in C++2b and C2x,
this adjusts the pedantic and extensions warning accordingly.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D130415
Files:
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Lex/PPDirectives.cpp
clang/test/Preprocessor/ext-pp-directive.c
Index: clang/test/Preprocessor/ext-pp-directive.c
===================================================================
--- clang/test/Preprocessor/ext-pp-directive.c
+++ clang/test/Preprocessor/ext-pp-directive.c
@@ -57,3 +57,16 @@
// For C++
// pre-cpp2b-pedantic-warning at -7 {{use of a '#elifndef' directive is a C++2b extension}}
// pre-cpp2b-compat-warning at -8 {{use of a '#elifndef' directive is incompatible with C++ standards before C++2b}}
+
+#warning foo
+// For C
+// pre-c2x-pedantic-warning at -2 {{#warning is a C2x extension}}
+// pre-c2x-pedantic-warning at -3 {{foo}}
+// pre-c2x-compat-warning at -4 {{#warning is incompatible with C standards before C2x}}
+// pre-c2x-compat-warning at -5 {{foo}}
+
+// For C++
+// pre-cpp2b-pedantic-warning at -8 {{#warning is a C++2b extension}}
+// pre-cpp2b-pedantic-warning at -9 {{foo}}
+// pre-cpp2b-compat-warning at -10 {{#warning is incompatible with C++ standards before C++2b}}
+// pre-cpp2b-compat-warning at -11 {{foo}}
Index: clang/lib/Lex/PPDirectives.cpp
===================================================================
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -1261,7 +1261,13 @@
return HandleIncludeNextDirective(SavedHash.getLocation(), Result);
case tok::pp_warning:
- Diag(Result, diag::ext_pp_warning_directive);
+ if(LangOpts.CPlusPlus)
+ Diag(Result, LangOpts.CPlusPlus2b ?
+ diag::warn_cxx2b_compat_warning_directive : diag::ext_pp_warning_directive) << /*C++2b*/ 1;
+ else
+ Diag(Result, LangOpts.C2x ?
+ diag::warn_c2x_compat_warning_directive : diag::ext_pp_warning_directive) << /*C2x*/ 0;
+
return HandleUserDiagnosticDirective(Result, true);
case tok::pp_ident:
return HandleIdentSCCSDirective(Result);
Index: clang/include/clang/Basic/DiagnosticLexKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticLexKinds.td
+++ clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -387,7 +387,15 @@
def ext_pp_ident_directive : Extension<"#ident is a language extension">;
def ext_pp_include_next_directive : Extension<
"#include_next is a language extension">, InGroup<GNUIncludeNext>;
-def ext_pp_warning_directive : Extension<"#warning is a language extension">;
+
+def ext_pp_warning_directive : Extension<
+ "#warning is a %select{C2x|C++2b}0 extension">;
+def warn_cxx2b_compat_warning_directive : Warning<
+ "#warning is incompatible with C++ standards before C++2b">,
+ InGroup<CXXPre2bCompat>, DefaultIgnore;
+def warn_c2x_compat_warning_directive : Warning<
+ "#warning is incompatible with C standards before C2x">,
+ InGroup<CPre2xCompat>, DefaultIgnore;
def ext_pp_extra_tokens_at_eol : ExtWarn<
"extra tokens at end of #%0 directive">, InGroup<ExtraTokens>;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130415.447047.patch
Type: text/x-patch
Size: 2845 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220723/af4b20b0/attachment-0001.bin>
More information about the cfe-commits
mailing list