diff options
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/SemaLookup.cpp | 3 | ||||
-rw-r--r-- | lib/Sema/SemaTemplateInstantiateDecl.cpp | 14 | ||||
-rw-r--r-- | lib/Sema/SemaTemplateInstantiateExpr.cpp | 28 |
3 files changed, 18 insertions, 27 deletions
diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 8fe287cb41..6212449744 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -687,7 +687,8 @@ Sema::CppLookupName(Scope *S, DeclarationName Name, if (R || RedeclarationOnly) return std::make_pair(true, R); } - if (Ctx->getParent() != Ctx->getLexicalParent()) { + if (Ctx->getParent() != Ctx->getLexicalParent() + || isa<CXXMethodDecl>(Ctx)) { // It is out of line defined C++ method or struct, we continue // doing name lookup in parent context. Once we will find namespace // or translation-unit we save it for possible checking diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index e69a1ce644..a5eb7793b8 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -697,9 +697,13 @@ static NamedDecl *findInstantiationOf(ASTContext &Ctx, NamedDecl * Sema::InstantiateDeclRef(NamedDecl *D, const TemplateArgumentList &TemplateArgs) { DeclContext *ParentDC = D->getDeclContext(); + if (isa<ParmVarDecl>(D) || ParentDC->isFunctionOrMethod()) { + // D is a local of some kind. Look into the map of local + // declarations to their instantiations. + return cast<NamedDecl>(CurrentInstantiationScope->getInstantiationOf(D)); + } - if (!ParentDC->isFileContext()) { - NamedDecl *ParentDecl = cast<NamedDecl>(ParentDC); + if (NamedDecl *ParentDecl = dyn_cast<NamedDecl>(ParentDC)) { ParentDecl = InstantiateDeclRef(ParentDecl, TemplateArgs); if (!ParentDecl) return 0; @@ -707,12 +711,6 @@ Sema::InstantiateDeclRef(NamedDecl *D, const TemplateArgumentList &TemplateArgs) ParentDC = cast<DeclContext>(ParentDecl); } - if (ParentDC->isFunctionOrMethod()) { - // D is a local of some kind. Look into the map of local - // variables to their instantiations. - return cast<NamedDecl>(CurrentInstantiationScope->getInstantiationOf(D)); - } - if (ParentDC != D->getDeclContext()) { // We performed some kind of instantiation in the parent context, // so now we need to look into the instantiated parent context to diff --git a/lib/Sema/SemaTemplateInstantiateExpr.cpp b/lib/Sema/SemaTemplateInstantiateExpr.cpp index a0fc25de92..726ac2b425 100644 --- a/lib/Sema/SemaTemplateInstantiateExpr.cpp +++ b/lib/Sema/SemaTemplateInstantiateExpr.cpp @@ -109,8 +109,7 @@ TemplateExprInstantiator::VisitUnresolvedFunctionNameExpr( Sema::OwningExprResult TemplateExprInstantiator::VisitDeclRefExpr(DeclRefExpr *E) { // FIXME: Recast this in terms of Sema::InstantiateDeclRef. - Decl *D = E->getDecl(); - ValueDecl *NewD = 0; + NamedDecl *D = E->getDecl(); if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) { assert(NTTP->getDepth() == 0 && "No nested templates yet"); const TemplateArgument &Arg = TemplateArgs[NTTP->getPosition()]; @@ -131,29 +130,22 @@ TemplateExprInstantiator::VisitDeclRefExpr(DeclRefExpr *E) { *Arg.getAsIntegral(), T, E->getSourceRange().getBegin())); - } else if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) { - NewD = SemaRef.CurrentInstantiationScope->getInstantiationOf(Parm); - } else if (VarDecl *Var = dyn_cast<VarDecl>(D)) { - if (Var->hasLocalStorage()) - NewD = SemaRef.CurrentInstantiationScope->getInstantiationOf(Var); - else - assert(false && - "FIXME: instantiation of non-local variable declarations"); - } else if (isa<FunctionDecl>(D)) { - // FIXME: Instantiate decl! - NewD = cast<ValueDecl>(D); - } else if (isa<OverloadedFunctionDecl>(D)) { - // FIXME: instantiate decls? - return SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(cast<NamedDecl>(D), + } + + if (OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(D)) { + // FIXME: instantiate each decl in the overload set + return SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Ovl, SemaRef.Context.OverloadTy, E->getLocation(), false, false)); - } else - assert(false && "FIXME: unhandled declaration reference kind"); + } + ValueDecl *NewD + = dyn_cast_or_null<ValueDecl>(SemaRef.InstantiateDeclRef(D, TemplateArgs)); if (!NewD) return SemaRef.ExprError(); + // FIXME: Build QualifiedDeclRefExpr? QualType T = NewD->getType(); return SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(NewD, T.getNonReferenceType(), |