r249090 - Don't try to get a CXXRecordDecl from a non-class TemplateSpecializationType.
Kaelyn Takata via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 1 15:38:52 PDT 2015
Author: rikka
Date: Thu Oct 1 17:38:51 2015
New Revision: 249090
URL: http://llvm.org/viewvc/llvm-project?rev=249090&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp
Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=249090&r1=249089&r2=249090&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Thu Oct 1 17:38:51 2015
@@ -3818,6 +3818,8 @@ void TypoCorrectionConsumer::addNamespac
SSIsTemplate = T->getTypeClass() == Type::TemplateSpecialization;
}
for (const auto *TI : SemaRef.getASTContext().types()) {
+ if (!TI->isClassType() && isa<TemplateSpecializationType>(TI))
+ continue;
if (CXXRecordDecl *CD = TI->getAsCXXRecordDecl()) {
CD = CD->getCanonicalDecl();
if (!CD->isDependentType() && !CD->isAnonymousStructOrUnion() &&
Modified: cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp?rev=249090&r1=249089&r2=249090&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp (original)
+++ cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp Thu Oct 1 17:38:51 2015
@@ -412,3 +412,13 @@ void AfterClassBody() {
_Static_assert(__alignof(s1) == 8, "");
_Static_assert(__alignof(s2) == 4, "");
}
+
+namespace PR24246 {
+template <typename TX> struct A {
+ template <bool> struct largest_type_select;
+ // expected-warning at +1 {{explicit specialization of 'largest_type_select' within class scope is a Microsoft extension}}
+ template <> struct largest_type_select<false> {
+ blah x; // expected-error {{unknown type name 'blah'}}
+ };
+};
+}
More information about the cfe-commits
mailing list