[Sema] Don't work around a malformed AST

We created a malformed TemplateSpecializationType: it was dependent but
had a RecordType as it's canonical type.  This would lead getAs to
crash.  r249090 worked around this but we should fix this for real by
providing a more appropriate template specialization type as the
canonical type.

This fixes PR24246.

llvm-svn: 253495
This commit is contained in:
David Majnemer 2015-11-18 19:49:19 +00:00
parent 87f03971fd
commit 678f50b622
2 changed files with 11 additions and 3 deletions

View File

@ -3890,8 +3890,6 @@ void TypoCorrectionConsumer::addNamespaces(
auto &Types = SemaRef.getASTContext().getTypes();
for (unsigned I = 0; I != Types.size(); ++I) {
const auto *TI = Types[I];
if (!TI->isClassType() && isa<TemplateSpecializationType>(TI))
continue;
if (CXXRecordDecl *CD = TI->getAsCXXRecordDecl()) {
CD = CD->getCanonicalDecl();
if (!CD->isDependentType() && !CD->isAnonymousStructOrUnion() &&

View File

@ -6408,7 +6408,17 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec,
if (!PrevDecl)
ClassTemplate->AddSpecialization(Specialization, InsertPos);
CanonType = Context.getTypeDeclType(Specialization);
if (CurContext->isDependentContext()) {
// -fms-extensions permits specialization of nested classes without
// fully specializing the outer class(es).
assert(getLangOpts().MicrosoftExt &&
"Only possible with -fms-extensions!");
TemplateName CanonTemplate = Context.getCanonicalTemplateName(Name);
CanonType = Context.getTemplateSpecializationType(
CanonTemplate, Converted.data(), Converted.size());
} else {
CanonType = Context.getTypeDeclType(Specialization);
}
}
// C++ [temp.expl.spec]p6: