diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 9e4977825078..87c4e70101ec 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -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); diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index a6bf82b590ba..a8546dd5eed4 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -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(FD)) + QualType BeforeToType; + if (const CXXConversionDecl *Conv = dyn_cast(FD)) { CastKind = CastExpr::CK_UserDefinedConversion; - else if (isa(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(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(),