Skip to content

Commit

Permalink
Merging r293678:
Browse files Browse the repository at this point in the history
------------------------------------------------------------------------
r293678 | ahatanak | 2017-01-31 11:53:32 -0800 (Tue, 31 Jan 2017) | 9 lines

[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: 293782
  • Loading branch information
zmodem committed Feb 1, 2017
1 parent 1494845 commit e87c6f4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
8 changes: 6 additions & 2 deletions clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
Expand Up @@ -4996,8 +4996,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,
Expand Down
8 changes: 7 additions & 1 deletion clang/lib/Sema/TreeTransform.h
Expand Up @@ -8818,12 +8818,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()
Expand Down
20 changes: 20 additions & 0 deletions clang/test/SemaCXX/destructor.cpp
Expand Up @@ -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();
}
}

0 comments on commit e87c6f4

Please sign in to comment.