Add warnings for empty blocks in if/else/do.

Saw a discussion of such in #qc and that gcc implemented it. I realized it
would be pretty easy to detect and very useful (I've made such mistakes at
times).
This commit is contained in:
Bill Currie 2013-09-30 18:09:04 +09:00
parent db460155e9
commit c88d1987a1

View file

@ -2222,6 +2222,14 @@ build_if_statement (int not, expr_t *test, expr_t *s1, expr_t *els, expr_t *s2)
expr_t *tl = new_label_expr (); expr_t *tl = new_label_expr ();
expr_t *fl = new_label_expr (); expr_t *fl = new_label_expr ();
if (els && !s2) {
warning (els,
"suggest braces around empty body in an else statement");
}
if (!els && !s1) {
warning (test,
"suggest braces around empty body in an if statement");
}
pr.source_line = test->line; pr.source_line = test->line;
pr.source_file = test->file; pr.source_file = test->file;
@ -2311,6 +2319,11 @@ build_do_while_statement (expr_t *statement, int not, expr_t *test,
string_t file = pr.source_file; string_t file = pr.source_file;
expr_t *do_while_expr; expr_t *do_while_expr;
if (!statement) {
warning (break_label,
"suggest braces around empty body in a do statement");
}
pr.source_line = test->line; pr.source_line = test->line;
pr.source_file = test->file; pr.source_file = test->file;