[cfe-commits] r86171 - in /cfe/trunk: lib/Sema/SemaType.cpp test/SemaTemplate/class-template-decl.cpp

Douglas Gregor dgregor at apple.com
Thu Nov 5 12:54:04 PST 2009


Author: dgregor
Date: Thu Nov  5 14:54:04 2009
New Revision: 86171

URL: http://llvm.org/viewvc/llvm-project?rev=86171&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/Sema/SemaType.cpp
    cfe/trunk/test/SemaTemplate/class-template-decl.cpp

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=86171&r1=86170&r2=86171&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Thu Nov  5 14:54:04 2009
@@ -229,7 +229,8 @@
   case DeclSpec::TST_enum:
   case DeclSpec::TST_union:
   case DeclSpec::TST_struct: {
-    TypeDecl *D = cast_or_null<TypeDecl>(static_cast<Decl *>(DS.getTypeRep()));
+    TypeDecl *D 
+      = dyn_cast_or_null<TypeDecl>(static_cast<Decl *>(DS.getTypeRep()));
     if (!D) {
       // This can happen in C++ with ambiguous lookups.
       Result = Context.IntTy;

Modified: cfe/trunk/test/SemaTemplate/class-template-decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/class-template-decl.cpp?rev=86171&r1=86170&r2=86171&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/class-template-decl.cpp (original)
+++ cfe/trunk/test/SemaTemplate/class-template-decl.cpp Thu Nov  5 14:54:04 2009
@@ -49,3 +49,5 @@
 void f() {
   template<typename T> class X; // expected-error{{expression}}
 }
+
+template<typename T> class X1 { } var; // expected-error{{declared as a template}}





More information about the cfe-commits mailing list