From 00a2759ca98e53daf2bad21ead8b4209f2858246 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Tue, 26 May 2009 04:57:27 +0000 Subject: [PATCH] Add a new CallExpr::getCallReturnType and use it in Expr::isLvalueInternal. No intended functionality change. llvm-svn: 72410 --- clang/include/clang/AST/Expr.h | 5 +++++ clang/lib/AST/Expr.cpp | 22 +++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index 494729cb659a..92f2025cb4dd 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -1006,6 +1006,11 @@ public: /// not, return 0. unsigned isBuiltinCall(ASTContext &Context) const; + /// getCallReturnType - Get the return type of the call expr. This is not + /// always the type of the expr itself, if the return type is a reference + /// type. + QualType getCallReturnType() const; + SourceLocation getRParenLoc() const { return RParenLoc; } void setRParenLoc(SourceLocation L) { RParenLoc = L; } diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index fbc8889567d3..6711faffe747 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -278,6 +278,16 @@ unsigned CallExpr::isBuiltinCall(ASTContext &Context) const { return FDecl->getBuiltinID(Context); } +QualType CallExpr::getCallReturnType() const { + QualType CalleeType = getCallee()->getType(); + if (const PointerType *FnTypePtr = CalleeType->getAsPointerType()) + CalleeType = FnTypePtr->getPointeeType(); + else if (const BlockPointerType *BPT = CalleeType->getAsBlockPointerType()) + CalleeType = BPT->getPointeeType(); + + const FunctionType *FnType = CalleeType->getAsFunctionType(); + return FnType->getResultType(); +} /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it /// corresponds to, e.g. "<<=". @@ -773,15 +783,9 @@ Expr::isLvalueResult Expr::isLvalueInternal(ASTContext &Ctx) const { // C++0x [expr.call]p10 // A function call is an lvalue if and only if the result type // is an lvalue reference. - QualType CalleeType = cast(this)->getCallee()->getType(); - if (const PointerType *FnTypePtr = CalleeType->getAsPointerType()) - CalleeType = FnTypePtr->getPointeeType(); - else if (const BlockPointerType *BPT = CalleeType->getAsBlockPointerType()) - CalleeType = BPT->getPointeeType(); - - if (const FunctionType *FnType = CalleeType->getAsFunctionType()) - if (FnType->getResultType()->isLValueReferenceType()) - return LV_Valid; + QualType ReturnType = cast(this)->getCallReturnType(); + if (ReturnType->isLValueReferenceType()) + return LV_Valid; break; }