From 20cd3937eef89045ba584539f665f401be5f5bea Mon Sep 17 00:00:00 2001 From: Kaelyn Takata Date: Thu, 1 Oct 2015 22:38:51 +0000 Subject: [PATCH] Don't try to get a CXXRecordDecl from a non-class TemplateSpecializationType. With -fms-extensions it is possible to have a non-class record that is a template specialization cause an assertion failure via the call to Type::getAsCXXRecordDecl. Fixes PR 24246. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249090 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaLookup.cpp | 2 ++ test/SemaCXX/MicrosoftExtensions.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index bda535bc65..05a347ecdf 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -3818,6 +3818,8 @@ void TypoCorrectionConsumer::addNamespaces( SSIsTemplate = T->getTypeClass() == Type::TemplateSpecialization; } for (const auto *TI : SemaRef.getASTContext().types()) { + if (!TI->isClassType() && isa(TI)) + continue; if (CXXRecordDecl *CD = TI->getAsCXXRecordDecl()) { CD = CD->getCanonicalDecl(); if (!CD->isDependentType() && !CD->isAnonymousStructOrUnion() && diff --git a/test/SemaCXX/MicrosoftExtensions.cpp b/test/SemaCXX/MicrosoftExtensions.cpp index db5e4586da..11f4f19556 100644 --- a/test/SemaCXX/MicrosoftExtensions.cpp +++ b/test/SemaCXX/MicrosoftExtensions.cpp @@ -412,3 +412,13 @@ void AfterClassBody() { _Static_assert(__alignof(s1) == 8, ""); _Static_assert(__alignof(s2) == 4, ""); } + +namespace PR24246 { +template struct A { + template struct largest_type_select; + // expected-warning@+1 {{explicit specialization of 'largest_type_select' within class scope is a Microsoft extension}} + template <> struct largest_type_select { + blah x; // expected-error {{unknown type name 'blah'}} + }; +}; +} -- 2.50.1