diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 31 | ||||
-rw-r--r-- | clang/lib/Sema/SemaInit.cpp | 6 | ||||
-rw-r--r-- | clang/lib/Sema/SemaInit.h | 11 |
3 files changed, 30 insertions, 18 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index d01516c77fe..09e1d6f4551 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -3181,21 +3181,22 @@ bool Sema::GatherArgumentsForCall(SourceLocation CallLoc, << Arg->getSourceRange())) return true; - // Pass the argument. - if (FDecl && i < FDecl->getNumParams()) { - ParmVarDecl *Param = FDecl->getParamDecl(i); - InitializedEntity Entity =InitializedEntity::InitializeParameter(Param); - OwningExprResult ArgE = PerformCopyInitialization(Entity, - SourceLocation(), - Owned(Arg)); - if (ArgE.isInvalid()) - return true; - - Arg = ArgE.takeAs<Expr>(); - } else { - if (PerformCopyInitialization(Arg, ProtoArgType, AA_Passing)) - return true; - } + // Pass the argument + ParmVarDecl *Param = 0; + if (FDecl && i < FDecl->getNumParams()) + Param = FDecl->getParamDecl(i); + + + InitializedEntity Entity = + Param? InitializedEntity::InitializeParameter(Param) + : InitializedEntity::InitializeParameter(ProtoArgType); + OwningExprResult ArgE = PerformCopyInitialization(Entity, + SourceLocation(), + Owned(Arg)); + if (ArgE.isInvalid()) + return true; + + Arg = ArgE.takeAs<Expr>(); if (!ProtoArgType->isReferenceType()) Arg = MaybeBindToTemporary(Arg).takeAs<Expr>(); diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index b72fede8bb2..9c85ceca74e 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -1807,8 +1807,12 @@ InitializedEntity InitializedEntity::InitializeBase(ASTContext &Context, DeclarationName InitializedEntity::getName() const { switch (getKind()) { - case EK_Variable: case EK_Parameter: + if (!VariableOrMember) + return DeclarationName(); + // Fall through + + case EK_Variable: case EK_Member: return VariableOrMember->getDeclName(); diff --git a/clang/lib/Sema/SemaInit.h b/clang/lib/Sema/SemaInit.h index c5ba57c7264..959c55e3d32 100644 --- a/clang/lib/Sema/SemaInit.h +++ b/clang/lib/Sema/SemaInit.h @@ -105,8 +105,9 @@ private: : Kind(EK_Parameter), Parent(0), Type(Parm->getType()), VariableOrMember(reinterpret_cast<DeclaratorDecl*>(Parm)) { } - /// \brief Create the initialization entity for the result of a function, - /// throwing an object, or performing an explicit cast. + /// \brief Create the initialization entity for the result of a + /// function, throwing an object, performing an explicit cast, or + /// initializing a parameter for which there is no declaration. InitializedEntity(EntityKind Kind, SourceLocation Loc, QualType Type) : Kind(Kind), Parent(0), Type(Type), Location(Loc.getRawEncoding()) { } @@ -130,6 +131,12 @@ public: return InitializedEntity(Parm); } + /// \brief Create the initialization entity for a parameter that is + /// only known by its type. + static InitializedEntity InitializeParameter(QualType Type) { + return InitializedEntity(EK_Parameter, SourceLocation(), Type); + } + /// \brief Create the initialization entity for the result of a function. static InitializedEntity InitializeResult(SourceLocation ReturnLoc, QualType Type) { |