[Sema] Don't crash when a field w/ a mem-initializer clashes with a record name

It is possible for a field and a class to have the same name.  In such
cases, performing lookup for the field might return a result set with
more than one entry.  An overzealous assertion fired, causing us to
crash instead of using the non-class lookup result.

This fixes PR28060.

llvm-svn: 272247
This commit is contained in:
David Majnemer 2016-06-09 05:26:56 +00:00
parent 2769bb5753
commit 76a256260e
2 changed files with 11 additions and 2 deletions

View File

@ -2637,8 +2637,7 @@ Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation,
Instantiation->getTemplateInstantiationPattern(); Instantiation->getTemplateInstantiationPattern();
DeclContext::lookup_result Lookup = DeclContext::lookup_result Lookup =
ClassPattern->lookup(Field->getDeclName()); ClassPattern->lookup(Field->getDeclName());
assert(Lookup.size() == 1); FieldDecl *Pattern = cast<FieldDecl>(Lookup.front());
FieldDecl *Pattern = cast<FieldDecl>(Lookup[0]);
InstantiateInClassInitializer(PointOfInstantiation, Field, Pattern, InstantiateInClassInitializer(PointOfInstantiation, Field, Pattern,
TemplateArgs); TemplateArgs);
} }

View File

@ -192,3 +192,13 @@ struct S {
int x[3] = {[N] = 3}; int x[3] = {[N] = 3};
}; };
} }
namespace PR28060 {
template <class T>
void foo(T v) {
struct s {
T *s = 0;
};
}
template void foo(int);
}