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


Neil Booth wrote:
> 
> Branko Čibej wrote:-
> 
> > @@ -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\
> 
> Hi Branko,
> 
> One nit - I think this bumps the string length to around 520 > 509.
> You should split it up, since only 509 chars is guaranteed portable
> (like the other strings in the help there).

O.K. I had to move the strings aroud a bit, so the patch is a bit
longer. I also took Kaveh's advice and left out the third patch.
This is against current CVS (updated a few minutes ago).

    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-18  Branko Cibej  <branko.cibej@hermes.si>

	* flags.h:  Declare warning flag warn_system_headers.
	* toplev.c:  Define it.
	(W_options): Add option -Wsystem-headers.
	* diagnostic.c (count_error): Test warn_system_headers.
	* invoke.texi:  Add description for -Wsystem-headers.



Index: 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/18 07:19:00
@@ -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: flags.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/flags.h,v
retrieving revision 1.50
diff -u -p -r1.50 flags.h
--- flags.h	2000/09/13 19:34:04	1.50
+++ flags.h	2000/09/18 07:19:00
@@ -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: invoke.texi
===================================================================
RCS file: /cvs/gcc/egcs/gcc/invoke.texi,v
retrieving revision 1.218
diff -u -p -r1.218 invoke.texi
--- invoke.texi	2000/09/16 13:29:43	1.218
+++ invoke.texi	2000/09/18 07:19:03
@@ -139,7 +139,7 @@ in the following sections.
 -Wmain  -Wmissing-declarations  -Wmissing-noreturn
 -Wmultichar  -Wno-import  -Wpacked  -Wpadded
 -Wparentheses -Wpointer-arith  -Wredundant-decls
--Wreturn-type -Wshadow  -Wsign-compare -Wswitch
+-Wreturn-type -Wshadow  -Wsign-compare -Wswitch -Wsystem-headers
 -Wtrigraphs -Wundef  -Wuninitialized  -Wunknown-pragmas -Wunreachable-code 
 -Wunused -Wunused-function -Wunused-label -Wunused-parameter
 -Wunused-variable -Wunused-value -Wwrite-strings
@@ -1705,6 +1705,18 @@ All of the above @samp{-W} options combi
 warnings about constructions that some users consider questionable, and
 that are easy to avoid (or modify to prevent the warning), even in
 conjunction with macros.
+
+@item -Wsystem-headers
+@cindex warnings from system headers
+@cindex system headers, warnings from
+Print warning messages for constructs found in system header files.
+Warnings from system headers are normally suppressed, on the assumption
+that they usually do not indicate real problems and would only make the
+compiler output harder to read.  Using this command line option tells
+GCC to emit warnings from system headers as if they occurred in user
+code.  However, note that using @samp{-Wall} in conjunction with this
+option will @emph{not} warn about unknown pragmas in system
+headers---for that, @samp{-Wunknown-pragmas} must also be used.
 @end table
 
 The following @samp{-W@dots{}} options are not implied by @samp{-Wall}.
Index: toplev.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/toplev.c,v
retrieving revision 1.380
diff -u -p -r1.380 toplev.c
--- toplev.c	2000/09/17 07:38:12	1.380
+++ toplev.c	2000/09/18 07:19:06
@@ -1307,6 +1307,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;
@@ -1406,6 +1410,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,
2000-09-18  Branko Cibej  <branko.cibej@hermes.si>

	* cpplib.h (cpp_options): New member warn_system_headers.
	* cpphash.h (CPP_PEDANTIC, CPP_WTRADITIONAL): Don't test
	CPP_IN_SYSTEM_HEADER.
	* cpplib.c (do_import, do_pragma_once): Likewise.
	* cpperror.c (_cpp_begin_message): Test warn_system_headers
	and CPP_IN_SYSTEM_HEADER.
	* cppinit.c (handle_option): Recognize -Wsystem_headers.
	(print_help): Describe -Wsystem_headers.
	* cpplex.c (lex_line): Reorganize condition so that warnings
	about C++ comments in system headers can be enabled. Remove
	label do_line_comment.



Index: 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/18 07:18:57
@@ -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: cpphash.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cpphash.h,v
retrieving revision 1.72
diff -u -p -r1.72 cpphash.h
--- cpphash.h	2000/09/12 03:42:29	1.72
+++ cpphash.h	2000/09/18 07:18:57
@@ -205,9 +205,9 @@ extern unsigned char _cpp_trigraph_map[U
   (CPP_BUFFER (PFILE) && CPP_BUFFER (PFILE)->inc \
    && CPP_BUFFER (PFILE)->inc->sysp)
 #define CPP_PEDANTIC(PF) \
-  (CPP_OPTION (PF, pedantic) && !CPP_IN_SYSTEM_HEADER (PF))
+  CPP_OPTION (PF, pedantic)
 #define CPP_WTRADITIONAL(PF) \
-  (CPP_OPTION (PF, warn_traditional) && !CPP_IN_SYSTEM_HEADER (PF))
+  CPP_OPTION (PF, warn_traditional)
 
 /* Hash step.  The hash calculation is duplicated in cpp_lookup and
    parse_name.  */
Index: cppinit.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cppinit.c,v
retrieving revision 1.109
diff -u -p -r1.109 cppinit.c
--- cppinit.c	2000/09/18 06:59:23	1.109
+++ cppinit.c	2000/09/18 07:18:57
@@ -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,36 +1739,38 @@ 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\
 "), stdout);
   fputs (_("\
+  -M                        Generate make dependencies\n\
+  -MM                       As -M, but ignore system header files\n\
   -MD                       As -M, but put output in a .d file\n\
   -MMD                      As -MD, but ignore system header files\n\
   -MG                       Treat missing header file as generated files\n\
   -g3                       Include #define and #undef directives in the output\n\
-  -D<macro>                 Define a <macro> with string '1' as its value\n\
-  -D<macro>=<val>           Define a <macro> with <val> as its value\n\
 "), stdout);
   fputs (_("\
+  -D<macro>                 Define a <macro> with string '1' as its value\n\
+  -D<macro>=<val>           Define a <macro> with <val> as its value\n\
   -A<question> (<answer>)   Assert the <answer> to <question>\n\
   -A-<question> (<answer>)  Disable the <answer> to <question>\n\
   -U<macro>                 Undefine <macro> \n\
   -v                        Display the version number\n\
-  -H                        Print the name of header files as they are used\n\
-  -C                        Do not discard comments\n\
 "), stdout);
   fputs (_("\
+  -H                        Print the name of header files as they are used\n\
+  -C                        Do not discard comments\n\
   -dM                       Display a list of macro definitions active at end\n\
   -dD                       Preserve macro definitions in output\n\
   -dN                       As -dD except that only the names are preserved\n\
   -dI                       Include #include directives in the output\n\
+"), stdout);
+  fputs (_("\
   -ftabstop=<number>        Distance between tab stops for column reporting\n\
   -P                        Do not generate #line directives\n\
   -$                        Do not allow '$' in identifiers\n\
-"), stdout);
-  fputs (_("\
   -remap                    Remap file names when including files.\n\
   --version                 Display version information\n\
   -h or --help              Display this information\n\
Index: cpplex.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cpplex.c,v
retrieving revision 1.97
diff -u -p -r1.97 cpplex.c
--- cpplex.c	2000/09/16 07:18:06	1.97
+++ cpplex.c	2000/09/18 07:18:59
@@ -1435,9 +1435,8 @@ lex_line (pfile, list)
 		     irrespective of conformance mode, because lots of
 		     broken systems do that and trying to clean it up
 		     in fixincludes is a nightmare.  */
-		  if (CPP_IN_SYSTEM_HEADER (pfile))
-		    goto do_line_comment;
-		  else if (CPP_OPTION (pfile, cplusplus_comments))
+                  if (CPP_OPTION (pfile, cplusplus_comments)
+                      || CPP_IN_SYSTEM_HEADER (pfile))
 		    {
 		      if (CPP_OPTION (pfile, c89) && CPP_PEDANTIC (pfile)
 			  && ! buffer->warned_cplusplus_comments)
@@ -1449,7 +1448,6 @@ lex_line (pfile, list)
 			  "(this will be reported only once per input file)");
 			  buffer->warned_cplusplus_comments = 1;
 			}
-		    do_line_comment:
 		      buffer->cur = cur;
 #if 0 /* Leave until new lexer in place.  */
 		      if (cur[-2] != c)
Index: cpplib.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cpplib.c,v
retrieving revision 1.202
diff -u -p -r1.202 cpplib.c
--- cpplib.c	2000/08/29 18:37:37	1.202
+++ cpplib.c	2000/09/18 07:18:59
@@ -366,8 +366,7 @@ do_import (pfile)
   const U_CHAR *str;
   int ab;
 
-  if (CPP_OPTION (pfile, warn_import)
-      && !CPP_IN_SYSTEM_HEADER (pfile) && !pfile->import_warning)
+  if (!pfile->import_warning && CPP_OPTION (pfile, warn_import))
     {
       pfile->import_warning = 1;
       cpp_warning (pfile,
@@ -787,8 +786,7 @@ do_pragma_once (pfile)
 
   /* Allow #pragma once in system headers, since that's not the user's
      fault.  */
-  if (!CPP_IN_SYSTEM_HEADER (pfile))
-    cpp_warning (pfile, "#pragma once is obsolete");
+  cpp_warning (pfile, "#pragma once is obsolete");
       
   if (CPP_PREV_BUFFER (ip) == NULL)
     cpp_warning (pfile, "#pragma once outside include file");
Index: cpplib.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cpplib.h,v
retrieving revision 1.121
diff -u -p -r1.121 cpplib.h
--- cpplib.h	2000/09/12 03:42:29	1.121
+++ cpplib.h	2000/09/18 07:18:59
@@ -349,6 +349,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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]