From: Douglas Gregor Date: Thu, 5 Nov 2009 20:54:04 +0000 (+0000) Subject: Be a little more careful when trying to extract a TypeDecl from a enum/class/struct... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c7621a64717203e1f7d5d79dbf548e590b32596c;p=clang Be a little more careful when trying to extract a TypeDecl from a enum/class/struct/union specifier; in invalid code, we may also see ClassTemplateDecls. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86171 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index f003127f14..93ef1ea2ea 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -229,7 +229,8 @@ static QualType ConvertDeclSpecToType(Declarator &TheDeclarator, Sema &TheSema){ case DeclSpec::TST_enum: case DeclSpec::TST_union: case DeclSpec::TST_struct: { - TypeDecl *D = cast_or_null(static_cast(DS.getTypeRep())); + TypeDecl *D + = dyn_cast_or_null(static_cast(DS.getTypeRep())); if (!D) { // This can happen in C++ with ambiguous lookups. Result = Context.IntTy; diff --git a/test/SemaTemplate/class-template-decl.cpp b/test/SemaTemplate/class-template-decl.cpp index 8c717ea16e..a8163127b0 100644 --- a/test/SemaTemplate/class-template-decl.cpp +++ b/test/SemaTemplate/class-template-decl.cpp @@ -49,3 +49,5 @@ public: void f() { template class X; // expected-error{{expression}} } + +template class X1 { } var; // expected-error{{declared as a template}}