flags.h: Declare warning flag warn_system_headers.
authorBranko Cibej <branko.cibej@hermes.si>
Mon, 25 Sep 2000 22:54:04 +0000 (00:54 +0200)
committerBenjamin Kosnik <bkoz@gcc.gnu.org>
Mon, 25 Sep 2000 22:54:04 +0000 (22:54 +0000)
2000-09-25  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.
* 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.

From-SVN: r36636

12 files changed:
gcc/ChangeLog
gcc/cpperror.c
gcc/cpphash.h
gcc/cppinit.c
gcc/cpplex.c
gcc/cpplib.c
gcc/cpplib.h
gcc/diagnostic.c
gcc/flags.h
gcc/invoke.texi
gcc/system.h
gcc/toplev.c

index c8898da0c692a9f79cd357718e67b8a095747e87..d2a5f1ed1b11a2726154b197cf7e11cf860d7164 100644 (file)
@@ -1,3 +1,22 @@
+2000-09-25  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.
+       * 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.
+
 Mon 25-Sep-2000 23:38:27 BST  Neil Booth  <neilb@earthling.net>
 
        * cpplex.c (save_comment): Only store the initial '/'
index a6c7b2dbf3e61985732ca613a743233d55f06a11..0d6dbfb1a9017569e89d7f70a1f32c6ad21bcb5f 100644 (file)
@@ -122,7 +122,9 @@ _cpp_begin_message (pfile, code, file, line, col)
     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, line, col)
     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 fed1cf4b49299e7a6c1db5d73614a995aba0570f..8787a6ce406c395b7f8965ec9301de907d5cbb47 100644 (file)
@@ -189,9 +189,9 @@ extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
   (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 196724aac046efaff130e4583491b627fc9e7bbb..d8ec597e4614e8b8a0fca7ebfbde4925e669f93a 100644 (file)
@@ -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 0c31560fd8f2281c8f88124f9db7e7f3f0674072..47dcdbc3a84f0bcb51969394405065a654fa9374 100644 (file)
@@ -1209,10 +1209,24 @@ lex_token (pfile, result)
             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)
-             && CPP_OPTION (pfile, c89) && CPP_PEDANTIC (pfile)
-             && !buffer->warned_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)
+               {
+                 cpp_pedwarn (pfile,
+                      "C++ style comments are not allowed in ISO C89");
+                 cpp_pedwarn (pfile,
+                      "(this will be reported only once per input file)");
+                 buffer->warned_cplusplus_comments = 1;
+               }
+             comment_start = buffer->cur;
+
+             /* Skip_line_comment updates buffer->read_ahead.  */
+             if (skip_line_comment (pfile))
+               cpp_warning_with_line (pfile, result->line, result->col,
+                                      "multi-line comment");
              cpp_pedwarn (pfile,
                           "C++ style comments are not allowed in ISO C89");
              cpp_pedwarn (pfile,
index d6fcf9bfb2d2184b09b6d86ec2a9d11cc398285b..0616e8a7d1d73c877d9d9f89a4b6ab4a48b71997 100644 (file)
@@ -383,8 +383,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,
@@ -801,9 +800,8 @@ 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");
   else
index c6f7ed34e8534951013133d6a6ab7c7ad83c0251..9b127136929f069fe0fbedce94fef22be95ea358 100644 (file)
@@ -359,6 +359,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 56ed9574bb99877bd315d262147bf24c06e58ccb..687375f517c41ee80ac76889bf9aaa30ca3f7412 100644 (file)
@@ -1051,7 +1051,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 6a87edb8e63b8cd61ba57822a8fc17190acf31ff..0a29c4b126d4eeeb6e5362e386d7aaa29680c967 100644 (file)
@@ -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 43aafbade452247d69437c691b27352d3b759e75..ccf2024fe7dbe4ef8de6a58a75a2d57edd01c10e 100644 (file)
@@ -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 combined.  This enables all the
 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 afaa977a0d97afc2bb78bab83655838b35de9f73..90a1fecba97796e800d0503cb6f056fd1fc9a99c 100644 (file)
@@ -426,7 +426,7 @@ extern PTR realloc PARAMS ((PTR, size_t));
 
 /* If the system doesn't provide strsignal, we get it defined in
    libiberty but no declaration is supplied. */
-#if defined (HAVE_DECL_STRSIGNAL) && !HAVE_DECL_STRSIGNAL
+#ifndef HAVE_STRSIGNAL
 # ifndef strsignal
 extern const char *strsignal PARAMS ((int));
 # endif
index 76ff873f13ad0a057a78c8fb3a3dc22564b7b602..6897d5fa2cf71059bdde92cfbdd9486fb9810efd 100644 (file)
@@ -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;
@@ -1410,6 +1414,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,