[clang] 2369a58 - [Clang] Fix handling of non-member functions in isNormalAssignmentOperator() (#115880)

via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 21 17:18:52 PST 2024


Author: smanna12
Date: 2024-11-21T19:18:49-06:00
New Revision: 2369a582c260aafd46ce09e75e884fb654fd330d

URL: https://github.com/llvm/llvm-project/commit/2369a582c260aafd46ce09e75e884fb654fd330d
DIFF: https://github.com/llvm/llvm-project/commit/2369a582c260aafd46ce09e75e884fb654fd330d.diff

LOG: [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.

Added: 
    

Modified: 
    clang/lib/Sema/CheckExprLifetime.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/CheckExprLifetime.cpp b/clang/lib/Sema/CheckExprLifetime.cpp
index 182ac806d3c13e..6cdd4dc629e50a 100644
--- a/clang/lib/Sema/CheckExprLifetime.cpp
+++ b/clang/lib/Sema/CheckExprLifetime.cpp
@@ -490,7 +490,7 @@ static bool isNormalAssignmentOperator(const FunctionDecl *FD) {
       if (MD && MD->isCXXInstanceMember())
         LHST = Ctx.getLValueReferenceType(MD->getFunctionObjectParameterType());
       else
-        LHST = MD->getParamDecl(0)->getType();
+        LHST = FD->getParamDecl(0)->getType();
       if (Ctx.hasSameType(RetT, LHST))
         return true;
     }


        


More information about the cfe-commits mailing list