]> granicus.if.org Git - clang/commitdiff
When performing an user defined conversion sequence, perform the initial standard...
authorAnders Carlsson <andersca@mac.com>
Tue, 15 Sep 2009 06:28:28 +0000 (06:28 +0000)
committerAnders Carlsson <andersca@mac.com>
Tue, 15 Sep 2009 06:28:28 +0000 (06:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81847 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclCXX.cpp
lib/Sema/SemaExprCXX.cpp

index 9e497782507828c6230fc5bfae9453c9742a014b..87c4e70101ecf1e98007d83b0895bc0e83d22635 100644 (file)
@@ -3243,12 +3243,6 @@ Sema::CompleteConstructorCall(CXXConstructorDecl *Constructor,
     Expr *Arg;
     if (i < NumArgs) {
       Arg = Args[i];
-      
-      // Pass the argument.
-      if (PerformCopyInitialization(Arg, ProtoArgType, "passing"))
-        return true;
-      
-      Args[i] = 0;
     } else {
       ParmVarDecl *Param = Constructor->getParamDecl(i);
       
index a6bf82b590ba2829283364e2012e7266688c9f36..a8546dd5eed41d21a9daaaecd4b360fdee176a3c 100644 (file)
@@ -971,17 +971,34 @@ Sema::PerformImplicitConversion(Expr *&From, QualType ToType,
       return true;
     break;
 
-  case ImplicitConversionSequence::UserDefinedConversion:
-    {
+  case ImplicitConversionSequence::UserDefinedConversion: {
+    
       FunctionDecl *FD = ICS.UserDefined.ConversionFunction;
       CastExpr::CastKind CastKind = CastExpr::CK_Unknown;
-      if (isa<CXXConversionDecl>(FD))
+      QualType BeforeToType;
+      if (const CXXConversionDecl *Conv = dyn_cast<CXXConversionDecl>(FD)) {
         CastKind = CastExpr::CK_UserDefinedConversion;
-      else if (isa<CXXConstructorDecl>(FD))
+        
+        // If the user-defined conversion is specified by a conversion function,
+        // the initial standard conversion sequence converts the source type to
+        // the implicit object parameter of the conversion function.
+        BeforeToType = Context.getTagDeclType(Conv->getParent());
+      } else if (const CXXConstructorDecl *Ctor = 
+                  dyn_cast<CXXConstructorDecl>(FD)) {
         CastKind = CastExpr::CK_ConstructorConversion;
+
+        // If the user-defined conversion is specified by a constructor, the 
+        // initial standard conversion sequence converts the source type to the
+        // type required by the argument of the constructor
+        BeforeToType = Ctor->getParamDecl(0)->getType();
+      }    
       else
         assert(0 && "Unknown conversion function kind!");
 
+      if (PerformImplicitConversion(From, BeforeToType, 
+                                    ICS.UserDefined.Before, "converting"))
+        return true;
+    
       OwningExprResult CastArg 
         = BuildCXXCastArgument(From->getLocStart(),
                                ToType.getNonReferenceType(),