static scope_t *scope = NULL;
static declaration_t *last_declaration = NULL;
static declaration_t *current_function = NULL;
+static declaration_t *current_init_decl = NULL;
static switch_statement_t *current_switch = NULL;
static statement_t *current_loop = NULL;
static statement_t *current_parent = NULL;
parse_initializer_env_t env;
env.type = orig_type;
env.must_be_constant = must_be_constant;
- env.declaration = declaration;
+ env.declaration = current_init_decl = declaration;
initializer_t *initializer = parse_initializer(&env);
+ current_init_decl = NULL;
if (env.type != orig_type) {
orig_type = env.type;
declaration->symbol, &declaration->source_position);
}
}
+ if (warning.init_self && declaration == current_init_decl) {
+ current_init_decl = NULL;
+ warningf(&source_position,
+ "variable '%#T' is initialized by itself",
+ declaration->type, declaration->symbol);
+ }
return expression;
}
.format = true,
.implicit_function_declaration = true,
.implicit_int = true,
+ .init_self = true,
.long_long = false,
.main = true,
.missing_declarations = false,
SET(format);
SET(implicit_function_declaration);
SET(implicit_int);
+ SET(init_self);
SET(main);
SET(nonnull);
SET(pointer_arith);
}
OPT("implicit-function-declaration", implicit_function_declaration);
OPT("implicit-int", implicit_int);
+ OPT("init-self", init_self);
OPT("long-long", long_long);
OPT("main", main);
OPT("missing-declarations", missing_declarations);
bool format:1; /**< Check printf-style format strings */
bool implicit_function_declaration:1; /**< Warn whenever a function is used before being declared */
bool implicit_int:1; /**< Warn when a declaration does not specify a type */
-#if 0 // TODO
bool init_self:1; /**< Warn about uninitialized variables which are initialized with themselves. */
+#if 0 // TODO
bool inline:1; /**< Warn if a function can not be inlined and it was declared as inline */
bool int_to_pointer_cast:1; /**< Warn if cast from integer to pointer of different size. */
#endif