From: Matthias Braun Date: Thu, 14 Jul 2011 08:24:57 +0000 (+0200) Subject: -Winit-self is useless (and produces wrong warnings), remove it and make it a compati... X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=7e1e9905b52db878b7f0be8efb8af52202934ade;hp=9fc7bb03d5232142420b4bff0d82f1a05bd64aba;p=cparser -Winit-self is useless (and produces wrong warnings), remove it and make it a compatibility nop-switch --- diff --git a/main.c b/main.c index 0db91f4..7ef6662 100644 --- a/main.c +++ b/main.c @@ -638,6 +638,7 @@ static void print_help_warnings(void) put_help("-w", "Disable all warnings"); put_help("-Wno-trigraphs", "Warn if input contains trigraphs"); put_help("-Wundef", "Warn if an undefined macro is used in an #if"); + put_help("-Winit-self", "Ignored (gcc compatibility)"); print_warning_opt_help(); } @@ -1163,6 +1164,8 @@ int main(int argc, char **argv) } else if (streq(option + 1, "no-trigraphs") || streq(option + 1, "undef")) { add_flag(&cppflags_obst, "%s", arg); + } else if (streq(option+1, "init-self")) { + /* ignored (gcc compatibility) */ } else { set_warning_opt(&option[1]); } diff --git a/parser.c b/parser.c index 3c5383b..d798e04 100644 --- a/parser.c +++ b/parser.c @@ -89,7 +89,6 @@ static scope_t *current_scope = NULL; /** Point to the current function declaration if inside a function. */ static function_t *current_function = NULL; static entity_t *current_entity = NULL; -static entity_t *current_init_decl = NULL; static switch_statement_t *current_switch = NULL; static statement_t *current_loop = NULL; static statement_t *current_parent = NULL; @@ -101,8 +100,6 @@ static label_statement_t *label_first = NULL; static label_statement_t **label_anchor = NULL; /** current translation unit. */ static translation_unit_t *unit = NULL; -/** true if we are in a type property context (evaluation only for type) */ -static bool in_type_prop = false; /** true if we are in an __extension__ context. */ static bool in_gcc_extension = false; static struct obstack temp_obst; @@ -2583,9 +2580,6 @@ static type_t *parse_typeof(void) expression_t *expression = NULL; - bool old_type_prop = in_type_prop; - in_type_prop = true; - switch (token.type) { case T_IDENTIFIER: if (is_typedef_symbol(token.symbol)) { @@ -2598,7 +2592,6 @@ static type_t *parse_typeof(void) } break; } - in_type_prop = old_type_prop; rem_anchor_token(')'); expect(')', end_error); @@ -4350,10 +4343,8 @@ static void parse_init_declarator_rest(entity_t *entity) env.type = orig_type; env.must_be_constant = must_be_constant; env.entity = entity; - current_init_decl = entity; initializer_t *initializer = parse_initializer(&env); - current_init_decl = NULL; if (entity->kind == ENTITY_VARIABLE) { /* §6.7.5:22 array initializers for arrays with unknown size @@ -6286,11 +6277,6 @@ static expression_t *parse_reference(void) check_deprecated(&pos, entity); - if (entity == current_init_decl && !in_type_prop && entity->kind == ENTITY_VARIABLE) { - current_init_decl = NULL; - warningf(WARN_INIT_SELF, &pos, "variable '%#N' is initialized by itself", entity); - } - return expression; } @@ -7040,10 +7026,6 @@ static expression_t *parse_typeprop(expression_kind_t const kind) eat(kind == EXPR_SIZEOF ? T_sizeof : T___alignof__); - /* we only refer to a type property, mark this case */ - bool old = in_type_prop; - in_type_prop = true; - type_t *orig_type; expression_t *expression; if (token.type == '(' && is_declaration_specifier(look_ahead(1))) { @@ -7100,7 +7082,6 @@ typeprop_expression: } end_error: - in_type_prop = old; return tp_expression; } diff --git a/warning.c b/warning.c index f8b3807..45b0025 100644 --- a/warning.c +++ b/warning.c @@ -43,7 +43,6 @@ static warning_switch_t warning[] = { [WARN_FORMAT] = { WARN_STATE_ON, "format" }, [WARN_IMPLICIT_FUNCTION_DECLARATION] = { WARN_STATE_ON, "implicit-function-declaration" }, [WARN_IMPLICIT_INT] = { WARN_STATE_ON, "implicit-int" }, - [WARN_INIT_SELF] = { WARN_STATE_ON, "init-self", }, [WARN_LONG_LONG] = { WARN_STATE_NONE, "long-long" }, [WARN_MAIN] = { WARN_STATE_ON, "main", }, [WARN_MISSING_DECLARATIONS] = { WARN_STATE_NONE, "missing-declarations", }, @@ -136,7 +135,6 @@ void set_warning_opt(const char *const opt) SET(WARN_FORMAT); SET(WARN_IMPLICIT_FUNCTION_DECLARATION); SET(WARN_IMPLICIT_INT); - SET(WARN_INIT_SELF); SET(WARN_MAIN); SET(WARN_MISSING_DECLARATIONS); SET(WARN_NONNULL); diff --git a/warning.h b/warning.h index 1d3acf8..74bfd10 100644 --- a/warning.h +++ b/warning.h @@ -56,7 +56,6 @@ typedef enum warning_t { WARN_FORMAT, /**< Check printf-style format strings */ WARN_IMPLICIT_FUNCTION_DECLARATION, /**< Warn whenever a function is used before being declared */ WARN_IMPLICIT_INT, /**< Warn when a declaration does not specify a type */ - WARN_INIT_SELF, /**< Warn about uninitialized variables which are initialized with themselves. */ #if 0 // TODO WARN_INLINE, /**< Warn if a function can not be inlined and it was declared as inline */ WARN_INT_TO_POINTER_CAST, /**< Warn if cast from integer to pointer of different size. */