[clang-tools-extra] r235932 - clang-tidy: [readability-else-after-return] Fix false positive. This

Daniel Jasper djasper at google.com
Mon Apr 27 15:42:21 PDT 2015


Author: djasper
Date: Mon Apr 27 17:42:20 2015
New Revision: 235932

URL: http://llvm.org/viewvc/llvm-project?rev=235932&view=rev
Log:
clang-tidy: [readability-else-after-return] Fix false positive. This
might be a little too strict now, but better be too strict than do the
wrong thing.

Modified:
    clang-tools-extra/trunk/clang-tidy/readability/ElseAfterReturnCheck.cpp
    clang-tools-extra/trunk/test/clang-tidy/readability-else-after-return.cpp

Modified: clang-tools-extra/trunk/clang-tidy/readability/ElseAfterReturnCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/ElseAfterReturnCheck.cpp?rev=235932&r1=235931&r2=235932&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/ElseAfterReturnCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/ElseAfterReturnCheck.cpp Mon Apr 27 17:42:20 2015
@@ -20,9 +20,11 @@ namespace readability {
 void ElseAfterReturnCheck::registerMatchers(MatchFinder *Finder) {
   // FIXME: Support continue, break and throw.
   Finder->addMatcher(
-      ifStmt(
-          hasThen(stmt(anyOf(returnStmt(), compoundStmt(has(returnStmt()))))),
-          hasElse(stmt().bind("else"))).bind("if"),
+      compoundStmt(
+          forEach(ifStmt(hasThen(stmt(anyOf(returnStmt(),
+                                            compoundStmt(has(returnStmt()))))),
+                         hasElse(stmt().bind("else")))
+                      .bind("if"))),
       this);
 }
 

Modified: clang-tools-extra/trunk/test/clang-tidy/readability-else-after-return.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-else-after-return.cpp?rev=235932&r1=235931&r2=235932&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/readability-else-after-return.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-else-after-return.cpp Mon Apr 27 17:42:20 2015
@@ -24,5 +24,12 @@ void f(int a) {
   } else {
     return;
   }
+
+  if (a > 0)
+    f(0);
+  else if (a > 10)
+    return;
+  else
+    f(0);
 }
 





More information about the cfe-commits mailing list