.Fl Wpointer-arith ,
.Fl Wredundant-decls ,
.Fl Wreturn-type ,
-.Fl Wshadow ,
+.Fl Wshadow-local ,
.Fl Wsign-compare ,
.Fl Wstrict-prototypes ,
.Fl Wswitch-enum ,
Activate some more warnings.
In particular these are
.Fl Wempty-statement ,
+.Fl Wshadow ,
.Fl Wunused-parameter ,
.Fl Wunused-value .
.It Fl Wfatal-errors
Warn about redundant declarations, i.e. multiple declarations of the same object or static forward declarations which have no use before their definition.
.It Fl Wshadow
Warn when a new declaration shadows another declaration with the same name in an outer scope.
+.It Fl Wshadow-local
+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 Wunreachable-code
Warn when the compiler determines that a statement (or in some cases a part thereof) will never be executed.
.It Fl Wunused
return previous_entity;
}
- if (warning.shadow) {
+ if (warning.shadow ||
+ (warning.shadow_local && previous_entity->base.parent_scope != file_scope)) {
warningf(pos, "%s '%Y' shadows %s (declared %P)",
get_entity_kind_name(entity->kind), symbol,
get_entity_kind_name(previous_entity->kind),
.return_type = true,
.s_are_errors = false,
.shadow = false,
+ .shadow_local = false,
.sign_compare = false,
.strict_prototypes = true,
.switch_default = false,
put_help("-Wredundant-decls", "");
put_help("-Wreturn-type", "");
put_help("-Wshadow", "");
+ put_help("-Wshadow-local", "");
put_help("-Wsign-compare", "");
put_help("-Wstrict-prototypes", "");
put_help("-Wswitch-default", "");
SET(pointer_arith);
SET(redundant_decls);
SET(return_type);
- SET(shadow);
+ SET(shadow_local);
SET(sign_compare);
SET(strict_prototypes);
SET(switch_enum);
// TODO SET(incomplete_aggregate_init);
// TODO SET(missing_field_initializers);
// TODO SET(pointless_comparison);
+ SET(shadow);
SET(unused_parameter);
SET(unused_value);
}
OPT("redundant-decls", redundant_decls);
OPT("return-type", return_type);
OPT("shadow", shadow);
+ OPT("shadow-local", shadow_local);
OPT("sign-compare", sign_compare);
OPT("strict-prototypes", strict_prototypes);
OPT("switch-default", switch_default);
bool sequence_point:1; /**< Warn about code that may have undefined semantics because of violations of sequence point rules */
#endif
bool shadow:1; /**< Warn whenever a local variable shadows another local variable, parameter or global variable or whenever a built-in function is shadowed */
+ bool shadow_local:1;
bool sign_compare:1; /**< Warn when a comparison between signed and unsigned values could produce an incorrect result when the signed value is converted to unsigned */
#if 0 // TODO
bool strict_aliasing:1; /**< Warn about code which might break the strict aliasing rules that the compiler is using for optimization. */