diff options
| author | Malcolm Parsons <malcolm.parsons@gmail.com> | 2017-11-28 14:57:47 +0000 |
|---|---|---|
| committer | Malcolm Parsons <malcolm.parsons@gmail.com> | 2017-11-28 14:57:47 +0000 |
| commit | 690f486bb72ecc4f96dcc2e8f8a39c8a175c97d4 (patch) | |
| tree | 7c4888acc072803689e0e7c5bf7c264f5195b697 | |
| parent | dc4a8734e84ea860b335752d952be77228b112dc (diff) | |
[clang-tidy] Ignore ExprWithCleanups when looking for else-after-throw
Summary:
The readability-else-after-return check was not warning about
an else after a throw of an exception that had arguments that needed
to be cleaned up.
Reviewers: aaron.ballman, alexfh, djasper
Reviewed By: aaron.ballman
Subscribers: lebedev.ri, klimek, xazax.hun, cfe-commits
Differential Revision: https://reviews.llvm.org/D40505
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@319174 91177308-0d34-0410-b5e6-96231b3b80d8
| -rw-r--r-- | clang-tidy/readability/ElseAfterReturnCheck.cpp | 3 | ||||
| -rw-r--r-- | test/clang-tidy/readability-else-after-return.cpp | 18 |
2 files changed, 20 insertions, 1 deletions
diff --git a/clang-tidy/readability/ElseAfterReturnCheck.cpp b/clang-tidy/readability/ElseAfterReturnCheck.cpp index 6c676636..8b5526ca 100644 --- a/clang-tidy/readability/ElseAfterReturnCheck.cpp +++ b/clang-tidy/readability/ElseAfterReturnCheck.cpp @@ -21,7 +21,8 @@ namespace readability { 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( diff --git a/test/clang-tidy/readability-else-after-return.cpp b/test/clang-tidy/readability-else-after-return.cpp index 782c929b..7e950928 100644 --- a/test/clang-tidy/readability-else-after-return.cpp +++ b/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 @@ void foo() { // 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++; + } } } |
