This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Desire gcc option to skip warnings in standard headers
- To: law at cygnus dot com
- Subject: Re: Desire gcc option to skip warnings in standard headers
- From: Branko Cibej <branko dot cibej at hermes dot si>
- Date: Tue, 30 Jun 1998 10:31:23 +0200
- Cc: Carlo Wood <carlo at runaway dot xs4all dot nl>, "egcs at cygnus dot com" <egcs at cygnus dot com>
- Organization: HERMES SoftLab
- References: <15746.899189654@hurl.cygnus.com>
Jeffrey A Law wrote:
> > That's trivial to do, of course -- most probably I should just invert the
> > meaning of the option. What about the name of the option, though? I don't like
> > -W(no-)system-headers, even though I thought it up myself...
> Warnings should be enabled by -W<foo> and disabled by -Wno-<foo>. I'm
> not aware of any that do not follow that convention and I don't think we
> should start making any now :-)
>
> The default behavior can either be on or off, that's separate from
> making -W<foo> and -Wno-<foo> do the right thing.
Right. The attached patches don't change the default behaviour, but inhibit warnings
from system headers if -Wno-system-headers. The patch for cpplib is separate because I
haven't really tested it -- I'd have to reconfigure the compiler. BTW, the patches are
against the latest snapshot.
--
Branko Cibej <branko.cibej@hermes.si>
HERMES SoftLab, Litijska 51, 1000 Ljubljana, Slovenia
phone: (++386 61) 186 53 49 fax: (++386 61) 186 52 70
1998-06-30 Branko Cibej <branko.cibej@hermes.si>
* flags.h: New extern declaration warn_system_headers.
* toplev.c: New warning flag warn_system_headers.
(W_options): Added initialisation for warn_system_headers.
(count_error): Inhibit warninhs from system headers if
warn_system_headers is 0.
* cccp.c: New warning flag warn_system_headers.
(INHIBIT_WARNINGS): New predicate, checks if warnings may be
printed.
(main): Handle option `-Wsystem-headers'.
(vwarning, vwarning_with_line, pedwarn_with_file_and_line):
Use INHIBIT_WARNINGS instead of flag inhibit_warnings.
* cpplib.h (CPP_INHIBIT_WARNINGS): New predicate, checks if
warnings may be printed.
(cpp_options): New member warn_system_headers.
* cpplib.c (cpp_options_init): Initialise member
warn_system_headers.
(cpp_handle_option): Handle option `-Wsystem-headers'.
(v_cpp_warning, v_cpp_warning_with_line,
cpp_pedwarn_with_file_and_line): Use CPP_INHIBIT_WARNINGS instead
of flag inhibit_warnings.
Index: gcc/flags.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/flags.h,v
retrieving revision 1.16
diff -p -r1.16 flags.h
*** flags.h 1998/06/25 15:14:16 1.16
--- flags.h 1998/06/30 07:41:27
*************** extern unsigned larger_than_size;
*** 137,142 ****
--- 137,146 ----
extern int warn_aggregate_return;
+ /* Print warnings generated in system headers */
+
+ extern int warn_system_headers;
+
/* Nonzero if generating code to do profiling. */
extern int profile_flag;
Index: gcc/toplev.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/toplev.c,v
retrieving revision 1.79
diff -p -r1.79 toplev.c
*** toplev.c 1998/06/27 15:51:49 1.79
--- toplev.c 1998/06/30 07:41:29
*************** int warn_inline;
*** 985,990 ****
--- 985,994 ----
int warn_aggregate_return;
+ /* Print warnings generated in system headers */
+
+ int warn_system_headers = 1;
+
/* Likewise for -W. */
struct { char *string; int *variable; int on_value;} W_options[] =
*************** struct { char *string; int *variable; in
*** 996,1002 ****
{"aggregate-return", &warn_aggregate_return, 1},
{"cast-align", &warn_cast_align, 1},
{"uninitialized", &warn_uninitialized, 1},
! {"inline", &warn_inline, 1}
};
/* Output files for assembler code (real compiler output)
--- 1000,1007 ----
{"aggregate-return", &warn_aggregate_return, 1},
{"cast-align", &warn_cast_align, 1},
{"uninitialized", &warn_uninitialized, 1},
! {"inline", &warn_inline, 1},
! {"system-headers", &warn_system_headers, 1}
};
/* Output files for assembler code (real compiler output)
*************** int
*** 1121,1127 ****
count_error (warningp)
int warningp;
{
! if (warningp && inhibit_warnings)
return 0;
if (warningp && !warnings_are_errors)
--- 1126,1133 ----
count_error (warningp)
int warningp;
{
! if (warningp
! && (inhibit_warnings || (in_system_header && !warn_system_headers)))
return 0;
if (warningp && !warnings_are_errors)
Index: gcc/cccp.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cccp.c,v
retrieving revision 1.28
diff -p -r1.28 cccp.c
*** cccp.c 1998/06/19 01:34:11 1.28
--- cccp.c 1998/06/30 07:41:32
*************** static int pedantic_errors;
*** 270,275 ****
--- 270,285 ----
static int inhibit_warnings = 0;
+ /* Print warnings generated in system headers */
+
+ static int warn_system_headers = 1;
+
+ /* Predicate to check whether warnings should be emitted */
+
+ #define INHIBIT_WARNINGS() \
+ (inhibit_warnings \
+ || (instack[indepth].system_header_p && !warn_system_headers))
+
/* Nonzero means warn if slash-star appears in a slash-star comment,
or if newline-backslash appears in a slash-slash comment. */
*************** main (argc, argv)
*** 1461,1466 ****
--- 1471,1480 ----
warn_trigraphs = 1;
warn_comments = 1;
}
+ else if (!strcmp (argv[i], "-Wsystem-headers"))
+ warn_system_headers = 1;
+ else if (!strcmp (argv[i], "-Wno-system-headers"))
+ warn_system_headers = 0;
break;
case 'M':
*************** vwarning (msg, args)
*** 9003,9009 ****
int i;
FILE_BUF *ip = NULL;
! if (inhibit_warnings)
return;
if (warnings_are_errors)
--- 9017,9023 ----
int i;
FILE_BUF *ip = NULL;
! if (INHIBIT_WARNINGS ())
return;
if (warnings_are_errors)
*************** vwarning_with_line (line, msg, args)
*** 9101,9107 ****
int i;
FILE_BUF *ip = NULL;
! if (inhibit_warnings)
return;
if (warnings_are_errors)
--- 9115,9121 ----
int i;
FILE_BUF *ip = NULL;
! if (INHIBIT_WARNINGS ())
return;
if (warnings_are_errors)
*************** pedwarn_with_file_and_line VPROTO ((char
*** 9185,9191 ****
#endif
va_list args;
! if (!pedantic_errors && inhibit_warnings)
return;
if (file) {
eprint_string (file, file_len);
--- 9199,9205 ----
#endif
va_list args;
! if (!pedantic_errors && INHIBIT_WARNINGS ())
return;
if (file) {
eprint_string (file, file_len);
Index: gcc/cpplib.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cpplib.h,v
retrieving revision 1.7
diff -p -r1.7 cpplib.h
*** cpplib.h 1998/06/23 13:51:33 1.7
--- cpplib.h 1998/06/30 07:41:06
*************** struct cpp_reader {
*** 313,318 ****
--- 313,324 ----
/* The bottom of the buffer stack. */
#define CPP_NULL_BUFFER(PFILE) (&(PFILE)->buffer_stack[CPP_STACK_MAX])
+ /* Predicate to check whether warnings should be emitted */
+ #define CPP_INHIBIT_WARNINGS(PFILE) \
+ (CPP_OPTIONS (PFILE)->inhibit_warnings \
+ || (CPP_BUFFER (PFILE)->system_header_p \
+ && !CPP_OPTIONS (PFILE)->warn_system_headers))
+
/* Pointed to by cpp_reader::data. */
struct cpp_options {
char *in_fname;
*************** struct cpp_options {
*** 384,389 ****
--- 390,399 ----
/* Nonzero means don't print warning messages. -w. */
char inhibit_warnings;
+
+ /* Print warnings generated in system headers */
+
+ char warn_system_headers;
/* Nonzero means warn if slash-star appears in a comment. */
Index: gcc/cpplib.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cpplib.c,v
retrieving revision 1.23
diff -p -r1.23 cpplib.c
*** cpplib.c 1998/06/23 13:51:32 1.23
--- cpplib.c 1998/06/30 07:41:08
*************** cpp_options_init (opts)
*** 770,775 ****
--- 770,776 ----
opts->chill = 0;
opts->pedantic_errors = 0;
opts->inhibit_warnings = 0;
+ opts->warn_system_headers = 1;
opts->warn_comments = 0;
opts->warn_import = 1;
opts->warnings_are_errors = 0;
*************** cpp_handle_option (pfile, argc, argv)
*** 6501,6506 ****
--- 6502,6511 ----
opts->warn_trigraphs = 1;
opts->warn_comments = 1;
}
+ else if (!strcmp (argv[i], "-Wsystem-headers"))
+ opts->warn_system_headers = 1;
+ else if (!strcmp (argv[i], "-Wno-system-headers"))
+ opts->warn_system_headers = 0;
break;
case 'M':
*************** v_cpp_warning (pfile, msg, ap)
*** 7390,7396 ****
const char *msg;
va_list ap;
{
! if (CPP_OPTIONS (pfile)->inhibit_warnings)
return;
if (CPP_OPTIONS (pfile)->warnings_are_errors)
--- 7395,7401 ----
const char *msg;
va_list ap;
{
! if (CPP_INHIBIT_WARNINGS (pfile))
return;
if (CPP_OPTIONS (pfile)->warnings_are_errors)
*************** v_cpp_warning_with_line (pfile, line, co
*** 7498,7504 ****
{
cpp_buffer *ip;
! if (CPP_OPTIONS (pfile)->inhibit_warnings)
return;
if (CPP_OPTIONS (pfile)->warnings_are_errors)
--- 7503,7509 ----
{
cpp_buffer *ip;
! if (CPP_INHIBIT_WARNINGS (pfile))
return;
if (CPP_OPTIONS (pfile)->warnings_are_errors)
*************** cpp_pedwarn_with_file_and_line VPROTO ((
*** 7591,7597 ****
#endif
if (!CPP_OPTIONS (pfile)->pedantic_errors
! && CPP_OPTIONS (pfile)->inhibit_warnings)
return;
if (file != NULL)
cpp_file_line_for_message (pfile, file, line, -1);
--- 7596,7602 ----
#endif
if (!CPP_OPTIONS (pfile)->pedantic_errors
! && CPP_INHIBIT_WARNINGS (pfile))
return;
if (file != NULL)
cpp_file_line_for_message (pfile, file, line, -1);