[clang-tools-extra] r319174 - [clang-tidy] Ignore ExprWithCleanups when looking for else-after-throw
Malcolm Parsons via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 28 06:57:47 PST 2017
Author: malcolm.parsons
Date: Tue Nov 28 06:57:47 2017
New Revision: 319174
URL: http://llvm.org/viewvc/llvm-project?rev=319174&view=rev
Log:
[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
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=319174&r1=319173&r2=319174&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/ElseAfterReturnCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/ElseAfterReturnCheck.cpp Tue Nov 28 06:57:47 2017
@@ -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(
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=319174&r1=319173&r2=319174&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 Tue Nov 28 06:57:47 2017
@@ -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++;
+ }
}
}
More information about the cfe-commits
mailing list