Skip to content

Commit 8348d72

Browse files
authored
[clang-tidy] Fix assert in performance-unnecessary-copy-init. (#96506)
`GetDirectCallee` can be null. Fixes #96498.
1 parent c393121 commit 8348d72

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
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/docs/ReleaseNotes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ Changes in existing checks
398398
analyzed, so the check now handles the common patterns
399399
`const auto e = (*vector_ptr)[i]` and `const auto e = vector_ptr->at(i);`.
400400
Calls to mutable function where there exists a `const` overload are also
401-
handled.
401+
handled. Fix crash in the case of a non-member operator call.
402402

403403
- Improved :doc:`readability-avoid-return-with-void-value
404404
<clang-tidy/checks/readability/avoid-return-with-void-value>` check by adding

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)