This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH/RFC] implement #pragma GCC warning


Hi, 

ever since PR24924 was fixed, #warning is now an error with C++ 
with -pedantic, and therefore doesn't serve the intended purpose anymore. 

I was wondering what to do with it.. one thing to avoid the hassle would be to 
implement #pragma GCC warning instead. 

A first attempt at a patch attached. Seems to work, but no testcase and no 
regtest run yet. Comments?


--- gcc/doc/cpp.texi
+++ gcc/doc/cpp.texi
@@ -3225,7 +3225,9 @@ an inconsistency and report it with @sam
 @findex #warning
 The directive @samp{#warning} is like @samp{#error}, but causes the
 preprocessor to issue a warning and continue preprocessing.  The tokens
-following @samp{#warning} are used as the warning message.
+following @samp{#warning} are used as the warning message. @samp{#pragma
+GCC warning} is an alias of this directive that does not trigger
+an extension warning.
 
 You might use @samp{#warning} in obsolete header files, with a message
 directing the user to the header file which should be used instead.
@@ -3427,6 +3429,11 @@ will not produce an error.
 @item #pragma GCC system_header
 This pragma takes no arguments.  It causes the rest of the code in the
 current file to be treated as if it came from a system header.
+
+@item #pragma GCC warning
+This pragma causes the following tokens to be printed as a compiler
+diagnostic message, similar to @samp{#warning}.
+
 @xref{System Headers}.
 
 @end ftable
--- libcpp/directives.c
+++ libcpp/directives.c
@@ -1007,6 +1009,14 @@ do_warning (cpp_reader *pfile)
   do_diagnostic (pfile, CPP_DL_WARNING_SYSHDR, 1);
 }
 
+static void
+do_pragma_warning (cpp_reader *pfile)
+{
+  /* We want #warning diagnostics to be emitted in system headers too.  */
+  _cpp_backup_tokens (pfile, 1);
+  do_diagnostic (pfile, CPP_DL_WARNING_SYSHDR, 0);
+}
+
 /* Report program identification.  */
 static void
 do_ident (cpp_reader *pfile)
@@ -1183,6 +1193,7 @@ _cpp_init_internal_pragmas (cpp_reader *
   register_pragma_internal (pfile, "GCC", "system_header",
 			    do_pragma_system_header);
   register_pragma_internal (pfile, "GCC", "dependency", 
do_pragma_dependency);
+  register_pragma_internal (pfile, "GCC", "warning", do_pragma_warning);
 }
 
 /* Return the number of registered pragmas in PE.  */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]