aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaTemplateInstantiate.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2009-11-21 08:51:07 +0000
committerJohn McCall <rjmccall@apple.com>2009-11-21 08:51:07 +0000
commitba13543329afac4a0d01304ec2ec4924d99306a6 (patch)
tree1533ccfa9a4fd586085e95f50ba52907d89bcd69 /lib/Sema/SemaTemplateInstantiate.cpp
parentbbd37c62e34db3f5a95c899723484a76c71d7757 (diff)
"Incremental" progress on using expressions, by which I mean totally ripping
into pretty much everything about overload resolution in order to wean BuildDeclarationNameExpr off LookupResult::getAsSingleDecl(). Replace UnresolvedFunctionNameExpr with UnresolvedLookupExpr, which generalizes the idea of a non-member lookup that we haven't totally resolved yet, whether by overloading, argument-dependent lookup, or (eventually) the presence of a function template in the lookup results. Incidentally fixes a problem with argument-dependent lookup where we were still performing ADL even when the lookup results contained something from a block scope. Incidentally improves a diagnostic when using an ObjC ivar from a class method. This just fell out from rewriting BuildDeclarationNameExpr's interaction with lookup, and I'm too apathetic to break it out. The only remaining uses of OverloadedFunctionDecl that I know of are in TemplateName and MemberExpr. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89544 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplateInstantiate.cpp')
-rw-r--r--lib/Sema/SemaTemplateInstantiate.cpp98
1 files changed, 54 insertions, 44 deletions
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp
index 58fe59e321..c61481f83d 100644
--- a/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/lib/Sema/SemaTemplateInstantiate.cpp
@@ -556,6 +556,9 @@ namespace {
bool isAddressOfOperand);
Sema::OwningExprResult TransformDeclRefExpr(DeclRefExpr *E,
bool isAddressOfOperand);
+ Sema::OwningExprResult TransformUnresolvedLookupExpr(
+ UnresolvedLookupExpr *E,
+ bool isAddressOfOperand);
Sema::OwningExprResult TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E,
bool isAddressOfOperand);
@@ -694,6 +697,55 @@ TemplateInstantiator::TransformPredefinedExpr(PredefinedExpr *E,
}
Sema::OwningExprResult
+TemplateInstantiator::TransformUnresolvedLookupExpr(UnresolvedLookupExpr *Old,
+ bool isAddressOfOperand) {
+ llvm::SmallVector<NamedDecl*, 16> InstDecls;
+
+ bool HasUnresolved = false;
+
+ for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
+ E = Old->decls_end(); I != E; ++I) {
+ NamedDecl *InstD = SemaRef.FindInstantiatedDecl(*I, TemplateArgs);
+ if (!InstD)
+ return SemaRef.ExprError();
+
+ // Expand using declarations.
+ if (isa<UsingDecl>(InstD)) {
+ UsingDecl *UD = cast<UsingDecl>(InstD);
+ for (UsingDecl::shadow_iterator UI = UD->shadow_begin(),
+ UE = UD->shadow_end(); UI != UE; ++UI) {
+ UsingShadowDecl *Shadow = *UI;
+ if (isa<UnresolvedUsingValueDecl>(Shadow->getUnderlyingDecl()))
+ HasUnresolved = true;
+ InstDecls.push_back(Shadow);
+ }
+
+ continue;
+ }
+
+ if (isa<UnresolvedUsingValueDecl>(InstD->getUnderlyingDecl()))
+ HasUnresolved = true;
+ InstDecls.push_back(InstD);
+ }
+
+ CXXScopeSpec SS;
+ NestedNameSpecifier *Qualifier = 0;
+ if (Old->getQualifier()) {
+ Qualifier = TransformNestedNameSpecifier(Old->getQualifier(),
+ Old->getQualifierRange());
+ if (!Qualifier)
+ return SemaRef.ExprError();
+
+ SS.setScopeRep(Qualifier);
+ SS.setRange(Old->getQualifierRange());
+ }
+
+ return SemaRef.BuildDeclarationNameExpr(&SS, Old->getNameLoc(),
+ Old->getName(), Old->requiresADL(),
+ InstDecls.data(), InstDecls.size());
+}
+
+Sema::OwningExprResult
TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E,
bool isAddressOfOperand) {
// FIXME: Clean this up a bit
@@ -788,46 +840,7 @@ TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E,
if (!InstD)
return SemaRef.ExprError();
- // Flatten using declarations into their shadow declarations.
- if (isa<UsingDecl>(InstD)) {
- UsingDecl *UD = cast<UsingDecl>(InstD);
-
- bool HasNonFunction = false;
-
- llvm::SmallVector<NamedDecl*, 8> Decls;
- for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
- E = UD->shadow_end(); I != E; ++I) {
- NamedDecl *TD = (*I)->getTargetDecl();
- if (!TD->isFunctionOrFunctionTemplate())
- HasNonFunction = true;
-
- Decls.push_back(TD);
- }
-
- if (Decls.empty())
- return SemaRef.ExprError();
-
- if (Decls.size() == 1)
- InstD = Decls[0];
- else if (!HasNonFunction) {
- OverloadedFunctionDecl *OFD
- = OverloadedFunctionDecl::Create(SemaRef.Context,
- UD->getDeclContext(),
- UD->getDeclName());
- for (llvm::SmallVectorImpl<NamedDecl*>::iterator I = Decls.begin(),
- E = Decls.end(); I != E; ++I)
- if (isa<FunctionDecl>(*I))
- OFD->addOverload(cast<FunctionDecl>(*I));
- else
- OFD->addOverload(cast<FunctionTemplateDecl>(*I));
-
- InstD = OFD;
- } else {
- // FIXME
- assert(false && "using declaration resolved to mixed set");
- return SemaRef.ExprError();
- }
- }
+ assert(!isa<UsingDecl>(InstD) && "decl ref instantiated to UsingDecl");
CXXScopeSpec SS;
NestedNameSpecifier *Qualifier = 0;
@@ -841,10 +854,7 @@ TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E,
SS.setRange(E->getQualifierRange());
}
- return SemaRef.BuildDeclarationNameExpr(E->getLocation(), InstD,
- /*FIXME:*/false,
- &SS,
- isAddressOfOperand);
+ return SemaRef.BuildDeclarationNameExpr(&SS, E->getLocation(), InstD);
}
Sema::OwningExprResult TemplateInstantiator::TransformCXXDefaultArgExpr(