]> granicus.if.org Git - clang/commitdiff
Get rid of the implicit deref call when calling member functions where the base is...
authorAnders Carlsson <andersca@mac.com>
Fri, 1 May 2009 18:34:30 +0000 (18:34 +0000)
committerAnders Carlsson <andersca@mac.com>
Fri, 1 May 2009 18:34:30 +0000 (18:34 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70562 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaOverload.cpp

index ab66939656ec879ee014bddceceb2d4f516e957c..eb4c4e6706dd1162bb60423fe872ff61db5a2c29 100644 (file)
@@ -1928,8 +1928,10 @@ Sema::TryObjectArgumentInitialization(Expr *From, CXXMethodDecl *Method) {
 
   // We need to have an object of class type.
   QualType FromType = From->getType();
-  if (!FromType->isRecordType())
-    return ICS;
+  if (const PointerType *PT = FromType->getAsPointerType())
+    FromType = PT->getPointeeType();
+
+  assert(FromType->isRecordType());
 
   // The implicit object parmeter is has the type "reference to cv X",
   // where X is the class of which the function is a member
@@ -1972,22 +1974,33 @@ Sema::TryObjectArgumentInitialization(Expr *From, CXXMethodDecl *Method) {
 /// expression.
 bool
 Sema::PerformObjectArgumentInitialization(Expr *&From, CXXMethodDecl *Method) {
-  QualType ImplicitParamType
-    = Method->getThisType(Context)->getAsPointerType()->getPointeeType();
+  QualType FromRecordType, DestType;
+  QualType ImplicitParamRecordType  = 
+    Method->getThisType(Context)->getAsPointerType()->getPointeeType();
+  
+  if (const PointerType *PT = From->getType()->getAsPointerType()) {
+    FromRecordType = PT->getPointeeType();
+    DestType = Method->getThisType(Context);
+  } else {
+    FromRecordType = From->getType();
+    DestType = ImplicitParamRecordType;
+  }
+
   ImplicitConversionSequence ICS 
     = TryObjectArgumentInitialization(From, Method);
   if (ICS.ConversionKind == ImplicitConversionSequence::BadConversion)
     return Diag(From->getSourceRange().getBegin(),
                 diag::err_implicit_object_parameter_init)
-       << ImplicitParamType << From->getType() << From->getSourceRange();
-
+       << ImplicitParamRecordType << FromRecordType << From->getSourceRange();
+  
   if (ICS.Standard.Second == ICK_Derived_To_Base &&
-      CheckDerivedToBaseConversion(From->getType(), ImplicitParamType,
+      CheckDerivedToBaseConversion(FromRecordType,
+                                   ImplicitParamRecordType,
                                    From->getSourceRange().getBegin(),
                                    From->getSourceRange()))
     return true;
 
-  ImpCastExprToType(From, ImplicitParamType, /*isLvalue=*/true);
+  ImpCastExprToType(From, DestType, /*isLvalue=*/true);
   return false;
 }
 
@@ -4048,10 +4061,7 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE,
 
   // Extract the object argument.
   Expr *ObjectArg = MemExpr->getBase();
-  if (MemExpr->isArrow())
-    ObjectArg = new (Context) UnaryOperator(ObjectArg, UnaryOperator::Deref,
-                     ObjectArg->getType()->getAsPointerType()->getPointeeType(),
-                                            ObjectArg->getLocStart());
+
   CXXMethodDecl *Method = 0;
   if (OverloadedFunctionDecl *Ovl 
         = dyn_cast<OverloadedFunctionDecl>(MemExpr->getMemberDecl())) {