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]

Re: [patch] New flag -Wsystem-headers


This is a followup to 

    http://gcc.gnu.org/ml/gcc-patches/2000-05/msg01044.html

I've updated the patch to current CVS. Bootstrapped on sparc-sun-solaris2.6

I also looked if I could add this flag to tradcpp, but I see no easy way to
check if we're truly parsing a system header. If someone (Zack?) knows how
to do that, I can make a patch for tradcpp.c.

    Brane

-- 
Branko Čibej                 <branko.cibej@hermes.si>
HERMES SoftLab, Litijska 51, 1000 Ljubljana, Slovenia
voice: (+386 1) 586 53 49     fax: (+386 1) 586 52 70
2000-09-10  Branko Cibej  <branko.cibej@hermes.si>

	* flags.h:  Declare warning flag warn_system_headers.
	* toplev.c:  Define it.
	(W_options): Add warning -Wsystem-headers.
	* diagnostic.c (count_errors): Test warn_system_headers.

	* cpplib.h (cpp_options): New member warn_system_headers.
	* cpperror.c (_cpp_begin_message): Test warn_system_headers.
	* cppinit.c (handle_option): Recognize -Wsystem-headers.
	(print_help): Describe -Wsystem-headers.


Index: gcc/cpperror.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cpperror.c,v
retrieving revision 1.37
diff -u -p -r1.37 cpperror.c
--- cpperror.c	2000/08/29 18:37:36	1.37
+++ cpperror.c	2000/09/10 15:04:05
@@ -122,7 +122,9 @@ _cpp_begin_message (pfile, code, file, l
     case WARNING:
       if (! CPP_OPTION (pfile, warnings_are_errors))
 	{
-	  if (CPP_OPTION (pfile, inhibit_warnings))
+	  if (CPP_OPTION (pfile, inhibit_warnings)
+              || (CPP_IN_SYSTEM_HEADER (pfile)
+                  && ! CPP_OPTION (pfile, warn_system_headers)))
 	    return 0;
 	  is_warning = 1;
 	}
@@ -138,7 +140,9 @@ _cpp_begin_message (pfile, code, file, l
     case PEDWARN:
       if (! CPP_OPTION (pfile, pedantic_errors))
 	{
-	  if (CPP_OPTION (pfile, inhibit_warnings))
+	  if (CPP_OPTION (pfile, inhibit_warnings)
+              || (CPP_IN_SYSTEM_HEADER (pfile)
+                  && ! CPP_OPTION (pfile, warn_system_headers)))
 	    return 0;
 	  is_warning = 1;
 	}
Index: gcc/cppinit.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cppinit.c,v
retrieving revision 1.108
diff -u -p -r1.108 cppinit.c
--- cppinit.c	2000/09/07 20:31:06	1.108
+++ cppinit.c	2000/09/10 15:04:05
@@ -1623,6 +1623,8 @@ cpp_handle_option (pfile, argc, argv)
 	    CPP_OPTION (pfile, warn_paste) = 1;
 	  else if (!strcmp (argv[i], "-Werror"))
 	    CPP_OPTION (pfile, warnings_are_errors) = 1;
+          else if (!strcmp (argv[i], "-Wsystem-headers"))
+            CPP_OPTION (pfile, warn_system_headers) = 1;
 	  else if (!strcmp (argv[i], "-Wno-traditional"))
 	    CPP_OPTION (pfile, warn_traditional) = 0;
 	  else if (!strcmp (argv[i], "-Wno-trigraphs"))
@@ -1639,6 +1641,8 @@ cpp_handle_option (pfile, argc, argv)
 	    CPP_OPTION (pfile, warn_paste) = 0;
 	  else if (!strcmp (argv[i], "-Wno-error"))
 	    CPP_OPTION (pfile, warnings_are_errors) = 0;
+          else if (!strcmp (argv[i], "-Wno-system-headers"))
+            CPP_OPTION (pfile, warn_system_headers) = 0;
 	  break;
  	}
     }
@@ -1735,6 +1739,8 @@ Switches:\n\
   -Wno-import               Do not warn about the use of #import\n\
   -Werror                   Treat all warnings as errors\n\
   -Wno-error                Do not treat warnings as errors\n\
+  -Wsystem-headers          Do not suppress warnings from system headers\n\
+  -Wno-system-headers       Suppress warnings from system headers\n\
   -Wall                     Enable all preprocessor warnings\n\
   -M                        Generate make dependencies\n\
   -MM                       As -M, but ignore system header files\n\
Index: gcc/cpplib.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cpplib.h,v
retrieving revision 1.120
diff -u -p -r1.120 cpplib.h
--- cpplib.h	2000/09/08 01:29:56	1.120
+++ cpplib.h	2000/09/10 15:04:05
@@ -352,6 +352,9 @@ struct cpp_options
   /* Nonzero means don't print warning messages.  */
   unsigned char inhibit_warnings;
 
+  /* Nonzero means don't suppress warnings from system headers.  */
+  unsigned char warn_system_headers;
+
   /* Nonzero means don't print error messages.  Has no option to
      select it, but can be set by a user of cpplib (e.g. fix-header).  */
   unsigned char inhibit_errors;
Index: gcc/diagnostic.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/diagnostic.c,v
retrieving revision 1.35
diff -u -p -r1.35 diagnostic.c
--- diagnostic.c	2000/09/06 18:43:35	1.35
+++ diagnostic.c	2000/09/10 15:04:05
@@ -1034,7 +1034,9 @@ int
 count_error (warningp)
      int warningp;
 {
-  if (warningp && inhibit_warnings)
+  if (warningp
+      && (inhibit_warnings
+          || (in_system_header && !warn_system_headers)))
     return 0;
 
   if (warningp && !warnings_are_errors)
Index: gcc/flags.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/flags.h,v
retrieving revision 1.49
diff -u -p -r1.49 flags.h
--- flags.h	2000/09/07 00:37:09	1.49
+++ flags.h	2000/09/10 15:04:05
@@ -79,6 +79,10 @@ extern int mem_report;
 
 extern int inhibit_warnings;
 
+/* Don't suppress warnings from system headers.  -Wsystem-headers.  */
+
+extern int warn_system_headers;
+
 /* Do print extra warnings (such as for uninitialized variables).  -W.  */
 
 extern int extra_warnings;
Index: gcc/toplev.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/toplev.c,v
retrieving revision 1.376
diff -u -p -r1.376 toplev.c
--- toplev.c	2000/09/07 00:37:09	1.376
+++ toplev.c	2000/09/10 15:04:06
@@ -1303,6 +1303,10 @@ target_options [] = TARGET_OPTIONS;
 
 int inhibit_warnings = 0;
 
+/* Don't suppress warnings from system headers.  -Wsystem-headers.  */
+
+int warn_system_headers = 0;
+
 /* Print various extra warnings.  -W.  */
 
 int extra_warnings = 0;
@@ -1402,6 +1406,7 @@ lang_independent_options W_options[] =
   {"unused-parameter", &warn_unused_parameter, 1, "Warn when a function parameter is unused" },
   {"unused-variable", &warn_unused_variable, 1, "Warn when a variable is unused" },
   {"unused-value", &warn_unused_value, 1, "Warn when an expression value is unused" },
+  {"system-headers", &warn_system_headers, 1, "Do not suppress warnings from system headers"},
   {"error", &warnings_are_errors, 1, ""},
   {"shadow", &warn_shadow, 1, "Warn when one local variable shadows another" },
   {"switch", &warn_switch, 1,



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