+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 '/'
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;
}
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;
}
(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. */
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"))
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;
}
}
-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\
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,
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,
/* 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
/* 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;
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)
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;
-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
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}.
/* 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
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;
{"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,