This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG559f07b87211: [Clang] Adjust extension warnings for #warning 
(authored by cor3ntin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130415

Files:
  clang/docs/ReleaseNotes.rst
  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@-7 {{use of a '#elifndef' directive is a C++2b 
extension}}
 // pre-cpp2b-compat-warning@-8 {{use of a '#elifndef' directive is 
incompatible with C++ standards before C++2b}}
+
+#warning foo
+// For C
+// pre-c2x-pedantic-warning@-2 {{#warning is a C2x extension}}
+// pre-c2x-pedantic-warning@-3 {{foo}}
+// pre-c2x-compat-warning@-4 {{#warning is incompatible with C standards 
before C2x}}
+// pre-c2x-compat-warning@-5 {{foo}}
+
+// For C++
+// pre-cpp2b-pedantic-warning@-8 {{#warning is a C++2b extension}}
+// pre-cpp2b-pedantic-warning@-9 {{foo}}
+// pre-cpp2b-compat-warning@-10 {{#warning is incompatible with C++ standards 
before C++2b}}
+// pre-cpp2b-compat-warning@-11 {{foo}}
Index: clang/lib/Lex/PPDirectives.cpp
===================================================================
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -1261,7 +1261,16 @@
       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>;
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -262,7 +262,7 @@
 - Added the ``-Wgnu-line-marker`` diagnostic flag (grouped under the ``-Wgnu``
   flag) which is a portability warning about use of GNU linemarker preprocessor
   directives. Fixes `Issue 55067 
<https://github.com/llvm/llvm-project/issues/55067>`_.
-- Using ``#elifdef`` and ``#elifndef`` that are incompatible with C/C++
+- Using ``#warning``, ``#elifdef`` and ``#elifndef`` that are incompatible 
with C/C++
   standards before C2x/C++2b are now warned via ``-pedantic``. Additionally,
   on such language mode, ``-Wpre-c2x-compat`` and ``-Wpre-c++2b-compat``
   diagnostic flags report a compatibility issue.


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@-7 {{use of a '#elifndef' directive is a C++2b extension}}
 // pre-cpp2b-compat-warning@-8 {{use of a '#elifndef' directive is incompatible with C++ standards before C++2b}}
+
+#warning foo
+// For C
+// pre-c2x-pedantic-warning@-2 {{#warning is a C2x extension}}
+// pre-c2x-pedantic-warning@-3 {{foo}}
+// pre-c2x-compat-warning@-4 {{#warning is incompatible with C standards before C2x}}
+// pre-c2x-compat-warning@-5 {{foo}}
+
+// For C++
+// pre-cpp2b-pedantic-warning@-8 {{#warning is a C++2b extension}}
+// pre-cpp2b-pedantic-warning@-9 {{foo}}
+// pre-cpp2b-compat-warning@-10 {{#warning is incompatible with C++ standards before C++2b}}
+// pre-cpp2b-compat-warning@-11 {{foo}}
Index: clang/lib/Lex/PPDirectives.cpp
===================================================================
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -1261,7 +1261,16 @@
       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>;
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -262,7 +262,7 @@
 - Added the ``-Wgnu-line-marker`` diagnostic flag (grouped under the ``-Wgnu``
   flag) which is a portability warning about use of GNU linemarker preprocessor
   directives. Fixes `Issue 55067 <https://github.com/llvm/llvm-project/issues/55067>`_.
-- Using ``#elifdef`` and ``#elifndef`` that are incompatible with C/C++
+- Using ``#warning``, ``#elifdef`` and ``#elifndef`` that are incompatible with C/C++
   standards before C2x/C++2b are now warned via ``-pedantic``. Additionally,
   on such language mode, ``-Wpre-c2x-compat`` and ``-Wpre-c++2b-compat``
   diagnostic flags report a compatibility issue.
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to