Skip to content

Commit 91e2c2a

Browse files
committedNov 28, 2017
[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 llvm-svn: 319174
1 parent f0ff20f commit 91e2c2a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed
 

‎clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ namespace readability {
2121
void ElseAfterReturnCheck::registerMatchers(MatchFinder *Finder) {
2222
const auto ControlFlowInterruptorMatcher =
2323
stmt(anyOf(returnStmt().bind("return"), continueStmt().bind("continue"),
24-
breakStmt().bind("break"), cxxThrowExpr().bind("throw")));
24+
breakStmt().bind("break"),
25+
expr(ignoringImplicit(cxxThrowExpr().bind("throw")))));
2526
Finder->addMatcher(
2627
compoundStmt(forEach(
2728
ifStmt(hasThen(stmt(

‎clang-tools-extra/test/clang-tidy/readability-else-after-return.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
// RUN: %check_clang_tidy %s readability-else-after-return %t -- -- -std=c++11 -fexceptions
22

3+
namespace std {
4+
struct string {
5+
string(const char *);
6+
~string();
7+
};
8+
} // namespace std
9+
10+
struct my_exception {
11+
my_exception(const std::string &s);
12+
};
13+
314
void f(int a) {
415
if (a > 0)
516
return;
@@ -85,5 +96,12 @@ void foo() {
8596
// CHECK-FIXES: {{^}} } // comment-9
8697
x++;
8798
}
99+
if (x) {
100+
throw my_exception("foo");
101+
} else { // comment-10
102+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not use 'else' after 'throw'
103+
// CHECK-FIXES: {{^}} } // comment-10
104+
x++;
105+
}
88106
}
89107
}

0 commit comments

Comments
 (0)