From fc195efd688f134fb58a540447f4ce67f9d6563e Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 21 Nov 2008 03:04:22 +0000 Subject: [PATCH] Cleanup memory management in overloading of operator->, slightly git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59791 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaOverload.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index a9411cc382..0a773719eb 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -3205,6 +3205,8 @@ Sema::BuildOverloadedArrowExpr(Expr *Base, SourceLocation OpLoc, } } + llvm::OwningPtr BasePtr(Base); + // Perform overload resolution. OverloadCandidateSet::iterator Best; switch (BestViableFunction(CandidateSet, Best)) { @@ -3215,29 +3217,28 @@ Sema::BuildOverloadedArrowExpr(Expr *Base, SourceLocation OpLoc, case OR_No_Viable_Function: if (CandidateSet.empty()) Diag(OpLoc, diag::err_typecheck_member_reference_arrow) - << Base->getType().getAsString() << Base->getSourceRange(); + << BasePtr->getType().getAsString() << BasePtr->getSourceRange(); else Diag(OpLoc, diag::err_ovl_no_viable_oper) - << "operator->" << Base->getSourceRange(); + << "operator->" << BasePtr->getSourceRange(); PrintOverloadCandidates(CandidateSet, /*OnlyViable=*/false); - delete Base; return true; case OR_Ambiguous: Diag(OpLoc, diag::err_ovl_ambiguous_oper) << "operator->" - << Base->getSourceRange(); + << BasePtr->getSourceRange(); PrintOverloadCandidates(CandidateSet, /*OnlyViable=*/true); - delete Base; return true; } // Convert the object parameter. CXXMethodDecl *Method = cast(Best->Function); - if (PerformObjectArgumentInitialization(Base, Method)) { - delete Base; + if (PerformObjectArgumentInitialization(Base, Method)) return true; - } + + // No concerns about early exits now. + BasePtr.take(); // Build the operator call. Expr *FnExpr = new DeclRefExpr(Method, Method->getType(), SourceLocation()); -- 2.40.0