]> granicus.if.org Git - clang/commitdiff
Don't try to get a CXXRecordDecl from a non-class TemplateSpecializationType.
authorKaelyn Takata <rikka@google.com>
Thu, 1 Oct 2015 22:38:51 +0000 (22:38 +0000)
committerKaelyn Takata <rikka@google.com>
Thu, 1 Oct 2015 22:38:51 +0000 (22:38 +0000)
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
test/SemaCXX/MicrosoftExtensions.cpp

index bda535bc6546467bbf89ef5d0f3e2ae62544cc3a..05a347ecdf3139987bc056bf4c854f42421f093b 100644 (file)
@@ -3818,6 +3818,8 @@ void TypoCorrectionConsumer::addNamespaces(
       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() &&
index db5e4586daf5ae34aff06fcbcf64e7746eb4bc02..11f4f195562a4ef294d9b133123a40692c6f0b9d 100644 (file)
@@ -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@+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'}}
+  };
+};
+}