Skip to content

Commit 5034dc9

Browse files
committed
[clang-tidy] Fix assert in performance-unnecessary-copy-init.
`GetDirectCallee` can be null. Fixes #96498.
1 parent db9e9ea commit 5034dc9

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ AST_MATCHER_P(DeclRefExpr, doesNotMutateObject, int, Indirections) {
296296
return false;
297297
}
298298
const auto *const Method =
299-
dyn_cast<CXXMethodDecl>(OpCall->getDirectCallee());
299+
dyn_cast_or_null<CXXMethodDecl>(OpCall->getDirectCallee());
300300

301301
if (Method == nullptr) {
302302
// This is not a member operator. Typically, a friend operator. These

clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,3 +906,12 @@ void negativeNonConstMemberExpr() {
906906
}
907907
}
908908

909+
910+
bool operator==(ExpensiveToCopyType, ExpensiveToCopyType);
911+
912+
template<typename T> bool OperatorWithNoDirectCallee(T t) {
913+
ExpensiveToCopyType a1;
914+
ExpensiveToCopyType a2 = a1;
915+
return a1 == t;
916+
}
917+

0 commit comments

Comments
 (0)