]> granicus.if.org Git - clang/commitdiff
Add a new CallExpr::getCallReturnType and use it in Expr::isLvalueInternal. No intend...
authorAnders Carlsson <andersca@mac.com>
Tue, 26 May 2009 04:57:27 +0000 (04:57 +0000)
committerAnders Carlsson <andersca@mac.com>
Tue, 26 May 2009 04:57:27 +0000 (04:57 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72410 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Expr.h
lib/AST/Expr.cpp

index 494729cb659a94652f4be88cd3b44cd17c5df0d0..92f2025cb4ddfd373ffaeb89608a8f535bdd99a2 100644 (file)
@@ -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; }
 
index fbc8889567d35966ff168fc51fc116c923178e58..6711faffe7476790e5712c7f42f55c939654bcb5 100644 (file)
@@ -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<CallExpr>(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<CallExpr>(this)->getCallReturnType();
+    if (ReturnType->isLValueReferenceType())
+      return LV_Valid;
 
     break;
   }