From 1d4fa1ea4a1bc593dd542ecd202fd947e355a06a Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Wed, 18 Nov 2015 19:49:19 +0000 Subject: [PATCH] [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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253495 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaLookup.cpp | 2 -- lib/Sema/SemaTemplate.cpp | 12 +++++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 3f36caa84b..1124d989c7 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -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(TI)) - continue; if (CXXRecordDecl *CD = TI->getAsCXXRecordDecl()) { CD = CD->getCanonicalDecl(); if (!CD->isDependentType() && !CD->isAnonymousStructOrUnion() && diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 8821088baa..c4c2814883 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -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: -- 2.40.0