[Sema] Transform a templated name before looking it up in

FindInstantiatedDecl or passing it to RebuildMemberExpr.

This fixes PR30361.

rdar://problem/17341274

Differential Revision: https://reviews.llvm.org/D24969

llvm-svn: 293678
This commit is contained in:
Akira Hatanaka 2017-01-31 19:53:32 +00:00
parent 0b009e8269
commit 59e3b43abc
3 changed files with 33 additions and 3 deletions

View File

@ -4990,8 +4990,12 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
NamedDecl *Result = nullptr;
// FIXME: If the name is a dependent name, this lookup won't necessarily
// find it. Does that ever matter?
if (D->getDeclName()) {
DeclContext::lookup_result Found = ParentDC->lookup(D->getDeclName());
if (auto Name = D->getDeclName()) {
DeclarationNameInfo NameInfo(Name, D->getLocation());
Name = SubstDeclarationNameInfo(NameInfo, TemplateArgs).getName();
if (!Name)
return nullptr;
DeclContext::lookup_result Found = ParentDC->lookup(Name);
Result = findInstantiationOf(Context, D, Found.begin(), Found.end());
} else {
// Since we don't have a name for the entity we're looking for,

View File

@ -8966,12 +8966,18 @@ TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
// base (and therefore couldn't do the check) and a
// nested-name-qualifier (and therefore could do the lookup).
NamedDecl *FirstQualifierInScope = nullptr;
DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
if (MemberNameInfo.getName()) {
MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
if (!MemberNameInfo.getName())
return ExprError();
}
return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
E->isArrow(),
QualifierLoc,
TemplateKWLoc,
E->getMemberNameInfo(),
MemberNameInfo,
Member,
FoundDecl,
(E->hasExplicitTemplateArgs()

View File

@ -431,3 +431,23 @@ class Invalid {
// The constructor definition should not have errors
Invalid::~Invalid() {}
namespace PR30361 {
template <typename T>
struct C1 {
~C1() {}
operator C1<T>* () { return nullptr; }
void foo1();
};
template<typename T>
void C1<T>::foo1() {
C1::operator C1<T>*();
C1::~C1();
}
void foo1() {
C1<int> x;
x.foo1();
}
}