new warning: -Wlocal-constants

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-08-21 10:18:55 +02:00
parent 92e8f08df3
commit 8fcc528ffa
3 changed files with 12 additions and 0 deletions

1
main.c
View file

@ -384,6 +384,7 @@ int main(int argc, char **argv) {
options_set(opts_warn, WARN_TOO_FEW_PARAMETERS, true);
options_set(opts_warn, WARN_MISSING_RETURN_VALUES, true);
options_set(opts_warn, WARN_USED_UNINITIALIZED, true);
options_set(opts_warn, WARN_LOCAL_CONSTANTS, true);
if (!options_parse(argc, argv)) {
return usage();

View file

@ -2115,6 +2115,16 @@ nextvar:
continue;
}
if (localblock && opts_standard == COMPILER_QCC) {
if (parsewarning(parser, WARN_LOCAL_CONSTANTS,
"initializing expression turns variable `%s` into a constant in this standard",
var->name) )
{
ast_value_delete(typevar);
return false;
}
}
if (parser->tok != '=') {
ast_value_delete(typevar);
parseerror(parser, "expected '=' or ';'");

View file

@ -11,3 +11,4 @@ GMQCC_DEFINE_FLAG(FIELD_REDECLARED)
GMQCC_DEFINE_FLAG(MISSING_RETURN_VALUES)
GMQCC_DEFINE_FLAG(TOO_FEW_PARAMETERS)
GMQCC_DEFINE_FLAG(LOCAL_SHADOWS)
GMQCC_DEFINE_FLAG(LOCAL_CONSTANTS)