Do not show it when if or else come from macros.
E.g.,
#define USED(A) if (A); else #define SOME_IF(A) if (A) void test() { // No warnings are shown in those cases now. USED(0); SOME_IF(0); }
Paths
| Differential D40185
Loosen -Wempty-body warning. ClosedPublic Authored by rnk on Nov 17 2017, 10:19 AM.
Details Summary Do not show it when if or else come from macros. #define USED(A) if (A); else #define SOME_IF(A) if (A) void test() { // No warnings are shown in those cases now. USED(0); SOME_IF(0); }
Diff Detail
Event TimelineComment Actions Why does passing the rparen location for the if condition fix the warning for IF_ELSE? I assumed that would refer to the else clause semicolon. This revision now requires changes to proceed.Nov 17 2017, 10:41 AM Comment Actions I'll go ahead and land this as requested to unblock things. Thanks for the patch, sorry for the trouble!
This revision is now accepted and ready to land.Nov 17 2017, 12:53 PM This revision now requires review to proceed.Nov 17 2017, 12:55 PM Closed by commit rL318556: Loosen -Wempty-body warning (authored by rnk). · Explain WhyNov 17 2017, 1:33 PM This revision was automatically updated to reflect the committed changes. Comment Actions
Using spelling locations fixes the else case, but breaks some of the if cases involving macros (catched by warn-empty-body.cpp test).
Revision Contents
Diff 123410 cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Parse/ParseStmt.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/test/SemaCXX/warn-empty-body.cpp
|