diff options
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/Sema.cpp | 3 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 11 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 17 | ||||
-rw-r--r-- | clang/lib/Sema/SemaInit.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 38 |
5 files changed, 46 insertions, 27 deletions
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index a57f1903576..081d45b61eb 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -811,8 +811,7 @@ void Sema::ActOnEndOfTranslationUnit() { VD->setInvalidDecl(); // No initialization is performed for a tentative definition. - InitializedEntity Entity = InitializedEntity::InitializeVariable(VD); - CheckCompleteVariableDeclaration(VD, Entity); + CheckCompleteVariableDeclaration(VD); // Notify the consumer that we've completed a tentative definition. if (!VD->isInvalidDecl()) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 4a68d60a1e2..66a55b2884d 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -9720,8 +9720,8 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, // Perform the initialization. ParenListExpr *CXXDirectInit = dyn_cast<ParenListExpr>(Init); - InitializedEntity Entity = InitializedEntity::InitializeVariable(VDecl); if (!VDecl->isInvalidDecl()) { + InitializedEntity Entity = InitializedEntity::InitializeVariable(VDecl); InitializationKind Kind = DirectInit ? CXXDirectInit @@ -9972,7 +9972,7 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, VDecl->setInitStyle(VarDecl::ListInit); } - CheckCompleteVariableDeclaration(VDecl, Entity); + CheckCompleteVariableDeclaration(VDecl); } /// ActOnInitializerError - Given that there was an error parsing an @@ -10257,7 +10257,7 @@ void Sema::ActOnUninitializedDecl(Decl *RealDecl, Var->setInitStyle(VarDecl::CallInit); } - CheckCompleteVariableDeclaration(Var, Entity); + CheckCompleteVariableDeclaration(Var); } } @@ -10334,8 +10334,7 @@ Sema::ActOnCXXForRangeIdentifier(Scope *S, SourceLocation IdentLoc, AttrEnd.isValid() ? AttrEnd : IdentLoc); } -void Sema::CheckCompleteVariableDeclaration(VarDecl *var, - InitializedEntity &Entity) { +void Sema::CheckCompleteVariableDeclaration(VarDecl *var) { if (var->isInvalidDecl()) return; if (getLangOpts().OpenCL) { @@ -10445,7 +10444,7 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var, if (!getLangOpts().CPlusPlus) return; if (auto *DD = dyn_cast<DecompositionDecl>(var)) - CheckCompleteDecompositionDeclaration(DD, Entity); + CheckCompleteDecompositionDeclaration(DD); QualType type = var->getType(); if (type->isDependentType()) return; diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index a1ef6b408fc..41fcffd8cc0 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -1065,10 +1065,10 @@ struct BindingDiagnosticTrap { }; } -static bool -checkTupleLikeDecomposition(Sema &S, ArrayRef<BindingDecl *> Bindings, - ValueDecl *Src, InitializedEntity &ParentEntity, - QualType DecompType, llvm::APSInt TupleSize) { +static bool checkTupleLikeDecomposition(Sema &S, + ArrayRef<BindingDecl *> Bindings, + ValueDecl *Src, QualType DecompType, + llvm::APSInt TupleSize) { if ((int64_t)Bindings.size() != TupleSize) { S.Diag(Src->getLocation(), diag::err_decomp_decl_wrong_number_bindings) << DecompType << (unsigned)Bindings.size() << TupleSize.toString(10) @@ -1152,8 +1152,7 @@ checkTupleLikeDecomposition(Sema &S, ArrayRef<BindingDecl *> Bindings, if (RefType.isNull()) return true; - InitializedEntity Entity = - InitializedEntity::InitializeBinding(ParentEntity, B, RefType); + InitializedEntity Entity = InitializedEntity::InitializeBinding(B, RefType); InitializationKind Kind = InitializationKind::CreateCopy(Loc, Loc); InitializationSequence Seq(S, Entity, Kind, Init); E = Seq.Perform(S, Entity, Kind, Init); @@ -1341,8 +1340,7 @@ static bool checkMemberDecomposition(Sema &S, ArrayRef<BindingDecl*> Bindings, return false; } -void Sema::CheckCompleteDecompositionDeclaration(DecompositionDecl *DD, - InitializedEntity &Entity) { +void Sema::CheckCompleteDecompositionDeclaration(DecompositionDecl *DD) { QualType DecompType = DD->getType(); // If the type of the decomposition is dependent, then so is the type of @@ -1386,8 +1384,7 @@ void Sema::CheckCompleteDecompositionDeclaration(DecompositionDecl *DD, return; case IsTupleLike::TupleLike: - if (checkTupleLikeDecomposition(*this, Bindings, DD, Entity, DecompType, - TupleSize)) + if (checkTupleLikeDecomposition(*this, Bindings, DD, DecompType, TupleSize)) DD->setInvalidDecl(); return; diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 6c156164bce..35accac4972 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -5886,7 +5886,9 @@ static const InitializedEntity *getEntityForTemporaryLifetimeExtension( return Entity; case InitializedEntity::EK_Binding: - return getEntityForTemporaryLifetimeExtension(Entity->getParent(), nullptr); + // Per [dcl.decomp]p3, the binding is treated as a variable of reference + // type. + return Entity; case InitializedEntity::EK_Parameter: case InitializedEntity::EK_Parameter_CF_Audited: diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 208afa6de60..1e28b350313 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -19,6 +19,7 @@ #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" #include "clang/AST/TypeLoc.h" +#include "clang/Sema/Initialization.h" #include "clang/Sema/Lookup.h" #include "clang/Sema/PrettyDeclStackTrace.h" #include "clang/Sema/Template.h" @@ -599,13 +600,27 @@ TemplateDeclInstantiator::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { } Decl *TemplateDeclInstantiator::VisitBindingDecl(BindingDecl *D) { - return BindingDecl::Create(SemaRef.Context, Owner, D->getLocation(), - D->getIdentifier()); + auto *NewBD = BindingDecl::Create(SemaRef.Context, Owner, D->getLocation(), + D->getIdentifier()); + SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, NewBD); + return NewBD; } Decl *TemplateDeclInstantiator::VisitDecompositionDecl(DecompositionDecl *D) { - // FIXME: Instantiate bindings and pass them in. - return VisitVarDecl(D, /*InstantiatingVarTemplate=*/false); + // Transform the bindings first. + SmallVector<BindingDecl*, 16> NewBindings; + for (auto *OldBD : D->bindings()) + NewBindings.push_back(cast<BindingDecl>(VisitBindingDecl(OldBD))); + ArrayRef<BindingDecl*> NewBindingArray = NewBindings; + + auto *NewDD = cast_or_null<DecompositionDecl>( + VisitVarDecl(D, /*InstantiatingVarTemplate=*/false, &NewBindingArray)); + + if (!NewDD || NewDD->isInvalidDecl()) + for (auto *NewBD : NewBindings) + NewBD->setInvalidDecl(); + + return NewDD; } Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D) { @@ -613,7 +628,8 @@ Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D) { } Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D, - bool InstantiatingVarTemplate) { + bool InstantiatingVarTemplate, + ArrayRef<BindingDecl*> *Bindings) { // Do substitution on the type of the declaration TypeSourceInfo *DI = SemaRef.SubstType(D->getTypeSourceInfo(), @@ -634,9 +650,15 @@ Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D, SemaRef.adjustContextForLocalExternDecl(DC); // Build the instantiated declaration. - VarDecl *Var = VarDecl::Create(SemaRef.Context, DC, D->getInnerLocStart(), - D->getLocation(), D->getIdentifier(), - DI->getType(), DI, D->getStorageClass()); + VarDecl *Var; + if (Bindings) + Var = DecompositionDecl::Create(SemaRef.Context, DC, D->getInnerLocStart(), + D->getLocation(), DI->getType(), DI, + D->getStorageClass(), *Bindings); + else + Var = VarDecl::Create(SemaRef.Context, DC, D->getInnerLocStart(), + D->getLocation(), D->getIdentifier(), DI->getType(), + DI, D->getStorageClass()); // In ARC, infer 'retaining' for variables of retainable type. if (SemaRef.getLangOpts().ObjCAutoRefCount && |