Skip to content

Commit 2369a58

Browse files
authored
[Clang] Fix handling of non-member functions in isNormalAssignmentOperator() (#115880)
This patch correctes the handling of non-member functions in the `isNormalAssignmentOperator` function within `CheckExprLifetime.cpp`. The previous implementation incorrectly assumed that `FunctionDecl` is always a `CXXMethodDecl`, leading to potential null pointer dereferencing. Change: - Correctly handle the case where `FD` is not a `CXXMethodDecl` by using `FD->getParamDecl(0)->getType()`. This fix ensures that the function correctly handles non-member assignment operators, such as: `struct S {}; void operator|=(S, S) {}` This change improves the robustness of the `isNormalAssignmentOperator` function by correctly identifying and handling different types of function declarations.
1 parent 836d2dc commit 2369a58

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

clang/lib/Sema/CheckExprLifetime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ static bool isNormalAssignmentOperator(const FunctionDecl *FD) {
490490
if (MD && MD->isCXXInstanceMember())
491491
LHST = Ctx.getLValueReferenceType(MD->getFunctionObjectParameterType());
492492
else
493-
LHST = MD->getParamDecl(0)->getType();
493+
LHST = FD->getParamDecl(0)->getType();
494494
if (Ctx.hasSameType(RetT, LHST))
495495
return true;
496496
}

0 commit comments

Comments
 (0)