diff options
| author | Douglas Gregor <dgregor@apple.com> | 2009-05-27 17:07:49 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2009-05-27 17:07:49 +0000 |
| commit | f98d9b60dbee3f523541b6f8831d1e549e4b0630 (patch) | |
| tree | df981cc93c08eeb53a951a26fed1d64fd80dc7a6 /clang/lib/Sema/SemaTemplateInstantiateExpr.cpp | |
| parent | bbcf90f9361ae3a7529f023697a01dcde31ad973 (diff) | |
| download | bcm5719-llvm-f98d9b60dbee3f523541b6f8831d1e549e4b0630.tar.gz bcm5719-llvm-f98d9b60dbee3f523541b6f8831d1e549e4b0630.zip | |
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
Diffstat (limited to 'clang/lib/Sema/SemaTemplateInstantiateExpr.cpp')
| -rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiateExpr.cpp | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/clang/lib/Sema/SemaTemplateInstantiateExpr.cpp b/clang/lib/Sema/SemaTemplateInstantiateExpr.cpp index a0fc25de922..726ac2b425e 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateExpr.cpp +++ b/clang/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(), |

