int test(int i) { if (i > 42); return 42; return i; } /* emptyif.cpp:2:14: warning: if statement has empty body [-Wempty-body] if (i > 42); ^ 1 warning generated. */
I think we had this warning and then removed it. Let me find the history which I think is in bugzilla already.
Yes, see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36478 .
(In reply to comment #2) > Yes, see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36478 . thanks. I tried -Wempty-body, gcc gives warning as expected: emptyif.cpp: In function 'int test(int)': emptyif.cpp:2:15: warning: suggest braces around empty body in an 'if' statement [-Wempty-body] if (i > 42);
I think that particular warning should be default (not -Wempty-body, but the warning about the if();). @Jason, Gabriel, do you agree?
Specifically about if(); without an else, sure.
Then, likely this could be resolved very quickly but what in means exactly to have the warning by default here? Change: if (!cp_lexer_next_token_is_keyword (parser->lexer, RID_ELSE)) warning_at (loc, OPT_Wempty_body, "suggest braces around " "empty body in an %<if%> statement"); to if (!cp_lexer_next_token_is_keyword (parser->lexer, RID_ELSE)) warning_at (loc, 0, "suggest braces around " "empty body in an %<if%> statement"); ?? It makes sense to me because I don't think somebody may want to suppress the warning and keep this kind of code, but wanted to confirm.
In any case, there are only 3 warnings in -Wempty-body. All of them seem worth to warn by default.
The problem of default warnings without options is that default warnings are often the most useful and, hence, the ones that people would like to make an error with -Werror=. Unfortunately, we don't have a -Werror=default to enable all of them.
Uhm, I was under the impression that the other 2 used to give problems and that's why we don't warn anymore by default. Bah. All in all, given that we have the warning anyway, I don't think this is really an high priority issue, if you see what I mean ;)
This warning is too noisy because it warns for: if(a) ; return 2; which is often the result of macro expansion. Clang specifically does not warn for this and suggests placing the ";" on a different line to silence the warning: warning: if statement has empty body [-Wempty-body] if(a); ^ note: put the semicolon on a separate line to silence this warning which seems a nicer way to silence the warning instead of ugly { ; }
(In reply to Paolo Carlini from comment #9) > Uhm, I was under the impression that the other 2 used to give problems and > that's why we don't warn anymore by default. Bah. All in all, given that we > have the warning anyway, I don't think this is really an high priority > issue, if you see what I mean ;) ok, changing importance from "normal" to "minor" then (and confirming)
(In reply to Manuel López-Ibáñez from comment #10) > Clang... suggests placing the ";" on a different line to silence > the warning: > > > warning: if statement has empty body [-Wempty-body] > if(a); > ^ > note: put the semicolon on a separate line to silence this warning > > which seems a nicer way to silence the warning instead of ugly { ; } That's a debatable opinion; I think the braces do a better job expressing grouping