Skip to content

Commit 3b1e3d2

Browse files
committed
[clang-tidy] Fix an unused-raii check crash on objective-c++.
Differential Revision: https://reviews.llvm.org/D83293
1 parent 0d656cb commit 3b1e3d2

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ void UnusedRaiiCheck::registerMatchers(MatchFinder *Finder) {
2727
// Look for temporaries that are constructed in-place and immediately
2828
// destroyed. Look for temporaries created by a functional cast but not for
2929
// those returned from a call.
30-
auto BindTemp =
31-
cxxBindTemporaryExpr(unless(has(ignoringParenImpCasts(callExpr()))))
32-
.bind("temp");
30+
auto BindTemp = cxxBindTemporaryExpr(
31+
unless(has(ignoringParenImpCasts(callExpr()))),
32+
unless(has(ignoringParenImpCasts(objcMessageExpr()))))
33+
.bind("temp");
3334
Finder->addMatcher(
3435
traverse(ast_type_traits::TK_AsIs,
3536
exprWithCleanups(
@@ -79,6 +80,7 @@ void UnusedRaiiCheck::check(const MatchFinder::MatchResult &Result) {
7980
auto Matches =
8081
match(expr(hasDescendant(typeLoc().bind("t"))), *E, *Result.Context);
8182
const auto *TL = selectFirst<TypeLoc>("t", Matches);
83+
assert(TL);
8284
D << FixItHint::CreateInsertion(
8385
Lexer::getLocForEndOfToken(TL->getEndLoc(), 0, *Result.SourceManager,
8486
getLangOpts()),
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: clang-tidy %s -checks=-*,bugprone-unused-raii -- | count 0
2+
3+
struct CxxClass {
4+
~CxxClass() {}
5+
};
6+
7+
@interface ObjcClass {
8+
}
9+
- (CxxClass)set:(int)p;
10+
@end
11+
12+
void test(ObjcClass *s) {
13+
[s set:1]; // ok, no crash, no diagnostic emitted.
14+
return;
15+
}

0 commit comments

Comments
 (0)