From f98d9b60dbee3f523541b6f8831d1e549e4b0630 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 27 May 2009 17:07:49 +0000 Subject: Improve name lookup for and template instantiation of declaration references. There are several smallish fixes here: - Make sure we look through template parameter scope when determining whether we're parsing a nested class (or nested class *template*). This makes sure that we delay parsing the bodies of inline member functions until after we're out of the outermost class (template) scope. - Since the bodies of member functions are always parsed "out-of-line", even when they were declared in-line, teach unqualified name lookup to look into the (semantic) parents. - Use the new InstantiateDeclRef to handle the instantiation of a reference to a declaration (in DeclRefExpr), which drastically simplifies template instantiation for DeclRefExprs. - When we're instantiating a ParmVarDecl, it must be in the current instantiation scope, so only look there. Also, remove the #if 0's and FIXME's from the dynarray example, which now compiles and executes thanks to Anders and Eli. llvm-svn: 72481 --- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'clang/lib/Sema/SemaTemplateInstantiateDecl.cpp') diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index e69a1ce644a..a5eb7793b84 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/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(D) || ParentDC->isFunctionOrMethod()) { + // D is a local of some kind. Look into the map of local + // declarations to their instantiations. + return cast(CurrentInstantiationScope->getInstantiationOf(D)); + } - if (!ParentDC->isFileContext()) { - NamedDecl *ParentDecl = cast(ParentDC); + if (NamedDecl *ParentDecl = dyn_cast(ParentDC)) { ParentDecl = InstantiateDeclRef(ParentDecl, TemplateArgs); if (!ParentDecl) return 0; @@ -707,12 +711,6 @@ Sema::InstantiateDeclRef(NamedDecl *D, const TemplateArgumentList &TemplateArgs) ParentDC = cast(ParentDecl); } - if (ParentDC->isFunctionOrMethod()) { - // D is a local of some kind. Look into the map of local - // variables to their instantiations. - return cast(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 -- cgit v1.2.3