From 317639a81c1c666ab67014d458da7cb57a554a92 Mon Sep 17 00:00:00 2001 From: Branko Cibej Date: Tue, 26 Sep 2000 00:54:04 +0200 Subject: [PATCH] flags.h: Declare warning flag warn_system_headers. 2000-09-25 Branko Cibej * 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 --- gcc/ChangeLog | 19 +++++++++++++++++++ gcc/cpperror.c | 8 ++++++-- gcc/cpphash.h | 4 ++-- gcc/cppinit.c | 22 ++++++++++++++-------- gcc/cpplex.c | 20 +++++++++++++++++--- gcc/cpplib.c | 8 +++----- gcc/cpplib.h | 3 +++ gcc/diagnostic.c | 4 +++- gcc/flags.h | 4 ++++ gcc/invoke.texi | 14 +++++++++++++- gcc/system.h | 2 +- gcc/toplev.c | 5 +++++ 12 files changed, 90 insertions(+), 23 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c8898da0c69..d2a5f1ed1b1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,22 @@ +2000-09-25 Branko Cibej + + * 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 * cpplex.c (save_comment): Only store the initial '/' diff --git a/gcc/cpperror.c b/gcc/cpperror.c index a6c7b2dbf3e..0d6dbfb1a90 100644 --- a/gcc/cpperror.c +++ b/gcc/cpperror.c @@ -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; } diff --git a/gcc/cpphash.h b/gcc/cpphash.h index fed1cf4b492..8787a6ce406 100644 --- a/gcc/cpphash.h +++ b/gcc/cpphash.h @@ -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. */ diff --git a/gcc/cppinit.c b/gcc/cppinit.c index 196724aac04..d8ec597e461 100644 --- a/gcc/cppinit.c +++ b/gcc/cppinit.c @@ -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 Define a with string '1' as its value\n\ - -D= Define a with as its value\n\ "), stdout); fputs (_("\ + -D Define a with string '1' as its value\n\ + -D= Define a with as its value\n\ -A () Assert the to \n\ -A- () Disable the to \n\ -U Undefine \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= 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\ diff --git a/gcc/cpplex.c b/gcc/cpplex.c index 0c31560fd8f..47dcdbc3a84 100644 --- a/gcc/cpplex.c +++ b/gcc/cpplex.c @@ -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, diff --git a/gcc/cpplib.c b/gcc/cpplib.c index d6fcf9bfb2d..0616e8a7d1d 100644 --- a/gcc/cpplib.c +++ b/gcc/cpplib.c @@ -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 diff --git a/gcc/cpplib.h b/gcc/cpplib.h index c6f7ed34e85..9b127136929 100644 --- a/gcc/cpplib.h +++ b/gcc/cpplib.h @@ -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; diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c index 56ed9574bb9..687375f517c 100644 --- a/gcc/diagnostic.c +++ b/gcc/diagnostic.c @@ -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) diff --git a/gcc/flags.h b/gcc/flags.h index 6a87edb8e63..0a29c4b126d 100644 --- a/gcc/flags.h +++ b/gcc/flags.h @@ -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; diff --git a/gcc/invoke.texi b/gcc/invoke.texi index 43aafbade45..ccf2024fe7d 100644 --- a/gcc/invoke.texi +++ b/gcc/invoke.texi @@ -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}. diff --git a/gcc/system.h b/gcc/system.h index afaa977a0d9..90a1fecba97 100644 --- a/gcc/system.h +++ b/gcc/system.h @@ -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 diff --git a/gcc/toplev.c b/gcc/toplev.c index 76ff873f13a..6897d5fa2cf 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -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, -- 2.30.2