flags.h: Declare warning flag warn_system_headers.

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
This commit is contained in:
Branko Cibej 2000-09-26 00:54:04 +02:00 committed by Benjamin Kosnik
parent 1c6d33efb4
commit 317639a81c
12 changed files with 90 additions and 23 deletions

View 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 '/'

View 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;
}

View 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. */

View 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\

View 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,

View 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

View 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;

View 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)

View 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;

View 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}.

View 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

View 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,