warning: Add the switch -Wsystem to show warnings in system headers.
authorChristoph Mallon <christoph.mallon@gmx.de>
Sat, 15 Dec 2012 10:24:58 +0000 (11:24 +0100)
committerChristoph Mallon <christoph.mallon@gmx.de>
Sat, 15 Dec 2012 11:29:09 +0000 (12:29 +0100)
Warnings in system headers are suppressed by default now.

cparser.1
diagnostic.c
parser.c
warning.c
warning.h

index 0eb7a6e..9a178c2 100644 (file)
--- a/cparser.1
+++ b/cparser.1
@@ -224,6 +224,9 @@ Warn when a new declaration shadows another declaration with the same name in an
 Like
 .Fl Wshadow ,
 but only warn if the shadowed declaration is not global, e.g. a local variable shadows a parameter or another local variable.
+.It Fl Wsystem
+Show warnings in system headers.
+By default, no warnings in system headers are shown.
 .It Fl Wunreachable-code
 Warn when the compiler determines that a statement (or in some cases a part thereof) will never be executed.
 .It Fl Wunused
index 5a74835..7447fda 100644 (file)
@@ -262,6 +262,9 @@ void errorf(const position_t *pos, const char *const fmt, ...)
 
 void warningf(warning_t const warn, position_t const* pos, char const *const fmt, ...)
 {
+       if (pos->is_system_header && !is_warn_on(WARN_SYSTEM))
+               return;
+
        va_list ap;
        va_start(ap, fmt);
        warning_switch_t const *const s = get_warn_switch(warn);
index ece0572..4be846a 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -4071,9 +4071,7 @@ warn_redundant_declaration: ;
                                                                     decl->attributes);
                                        if (has_new_attrs) {
                                                merge_in_attributes(decl, prev_decl->attributes);
-                                       } else if (!is_definition        &&
-                                                       is_type_valid(prev_type) &&
-                                                       !pos->is_system_header) {
+                                       } else if (!is_definition && is_type_valid(prev_type)) {
                                                warningf(WARN_REDUNDANT_DECLS, pos, "redundant declaration for '%N' (declared %P)", entity, ppos);
                                        }
                                } else if (current_function == NULL) {
index d74ec4c..67ee728 100644 (file)
--- a/warning.c
+++ b/warning.c
@@ -54,6 +54,7 @@ static warning_switch_t warning[] = {
        [WARN_STRICT_PROTOTYPES]             = { WARN_STATE_ON,   "strict-prototypes"             },
        [WARN_SWITCH_DEFAULT]                = { WARN_STATE_NONE, "switch-default",               },
        [WARN_SWITCH_ENUM]                   = { WARN_STATE_NONE, "switch-enum",                  },
+       [WARN_SYSTEM]                        = { WARN_STATE_NONE, "system",                       },
        [WARN_TRADITIONAL]                   = { WARN_STATE_NONE, "traditional"                   },
        [WARN_UNINITIALIZED]                 = { WARN_STATE_ON,   "uninitialized",                },
        [WARN_UNKNOWN_PRAGMAS]               = { WARN_STATE_ON,   "unknown-pragmas",              },
index 355953f..b0cd192 100644 (file)
--- a/warning.h
+++ b/warning.h
@@ -86,6 +86,7 @@ typedef enum warning_t {
        WARN_STRICT_PROTOTYPES,             /**< Warn if a function declaration has an unspecified parameter list */
        WARN_SWITCH_DEFAULT,                /**< Warn whenever a 'switch' statement does not have a 'default' case */
        WARN_SWITCH_ENUM,                   /**< Warn about 'switch' statements with an enum as index type and missing case labels or case labels outside the enum range TODO has an alias -Wswitch? */
+       WARN_SYSTEM,                        /**< Show warnings in system headers. */
        WARN_TRADITIONAL,                   /**< Warn about certain constructs that behave differently in traditional and ISO C */
 #if 0 // TODO
        WARN_UNDEF,                         /**< Warn if an undefined identifier is evaluated in an '#if' directive */