[PATCH] D40505: [clang-tidy] Ignore ExprWithCleanups when looking for else-after-throw

Malcolm Parsons via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 28 06:58:22 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE319174: [clang-tidy] Ignore ExprWithCleanups when looking for else-after-throw (authored by malcolm.parsons).

Changed prior to commit:
  https://reviews.llvm.org/D40505?vs=124566&id=124567#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40505

Files:
  clang-tidy/readability/ElseAfterReturnCheck.cpp
  test/clang-tidy/readability-else-after-return.cpp


Index: clang-tidy/readability/ElseAfterReturnCheck.cpp
===================================================================
--- clang-tidy/readability/ElseAfterReturnCheck.cpp
+++ clang-tidy/readability/ElseAfterReturnCheck.cpp
@@ -21,7 +21,8 @@
 void ElseAfterReturnCheck::registerMatchers(MatchFinder *Finder) {
   const auto ControlFlowInterruptorMatcher =
       stmt(anyOf(returnStmt().bind("return"), continueStmt().bind("continue"),
-                 breakStmt().bind("break"), cxxThrowExpr().bind("throw")));
+                 breakStmt().bind("break"),
+                 expr(ignoringImplicit(cxxThrowExpr().bind("throw")))));
   Finder->addMatcher(
       compoundStmt(forEach(
           ifStmt(hasThen(stmt(
Index: test/clang-tidy/readability-else-after-return.cpp
===================================================================
--- test/clang-tidy/readability-else-after-return.cpp
+++ test/clang-tidy/readability-else-after-return.cpp
@@ -1,5 +1,16 @@
 // RUN: %check_clang_tidy %s readability-else-after-return %t -- -- -std=c++11 -fexceptions
 
+namespace std {
+struct string {
+  string(const char *);
+  ~string();
+};
+} // namespace std
+
+struct my_exception {
+  my_exception(const std::string &s);
+};
+
 void f(int a) {
   if (a > 0)
     return;
@@ -85,5 +96,12 @@
     // CHECK-FIXES: {{^}}    } // comment-9
       x++;
     }
+    if (x) {
+      throw my_exception("foo");
+    } else { // comment-10
+    // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not use 'else' after 'throw'
+    // CHECK-FIXES: {{^}}    } // comment-10
+      x++;
+    }
   }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40505.124567.patch
Type: text/x-patch
Size: 1588 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171128/60afc8fc/attachment.bin>


More information about the cfe-commits mailing list