mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 04:42:32 +00:00
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:
parent
db460155e9
commit
c88d1987a1
1 changed files with 13 additions and 0 deletions
|
@ -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 *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_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;
|
||||
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_file = test->file;
|
||||
|
||||
|
|
Loading…
Reference in a new issue