statement_t *last_statement = NULL;
+ bool only_decls_so_far = true;
while (token.type != '}' && token.type != T_EOF) {
statement_t *sub_statement = intern_parse_statement();
if (is_invalid_statement(sub_statement)) {
continue;
}
+ if (warning.declaration_after_statement) {
+ if (sub_statement->kind != STATEMENT_DECLARATION) {
+ only_decls_so_far = false;
+ } else if (!only_decls_so_far) {
+ warningf(&sub_statement->base.source_position,
+ "ISO C90 forbids mixed declarations and code");
+ }
+ }
+
if (last_statement != NULL) {
last_statement->base.next = sub_statement;
} else {
warning_t warning = {
.attribute = true,
.char_subscripts = true,
+ .declaration_after_statement = false,
.deprecated_declarations = true,
.empty_statement = false,
.fatal_errors = false,
}
OPT("attribute", attribute);
OPT("char-subscripts", char_subscripts);
+ OPT("declaration-after-statement", declaration_after_statement);
OPT("deprecated-declarations", deprecated_declarations);
OPT("empty-statement", empty_statement);
OPT("error", s_are_errors);
bool cast_align:1; /**< Warn whenever a pointer is cast such that the required alignment of the target is increased */
bool cast_qual:1; /**< Warn whenever a pointer is cast so as to remove a type qualifier from the target type */
bool conversion:1; /**< Warn if a prototype causes a type conversion that is different from what would happen to the same argument in the absence of a prototype */
- bool declaration_after_statement:1; /**< Warn when a declaration is found after a statement in a block */
#endif
+ bool declaration_after_statement:1; /**< Warn when a declaration is found after a statement in a block */
bool deprecated_declarations:1; /* TODO implement for types */ /**< Warn about uses of functions, variables and types marked as deprecated by using the 'deprecated' attribute */
#if 0 // TODO
bool div_by_zero:1; /**< Warn about compile-time integer division by zero */