[cfe-commits] r101381 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExprCXX.cpp test/SemaCXX/exceptions.cpp

Douglas Gregor dgregor at apple.com
Thu Apr 15 11:05:39 PDT 2010


Author: dgregor
Date: Thu Apr 15 13:05:39 2010
New Revision: 101381

URL: http://llvm.org/viewvc/llvm-project?rev=101381&view=rev
Log:
Diagnose attempts to throw an abstract class type.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/test/SemaCXX/exceptions.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=101381&r1=101380&r2=101381&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Apr 15 13:05:39 2010
@@ -402,6 +402,8 @@
   "%select{return|parameter|variable|field}0 type %1 is an abstract class">;
 def err_allocation_of_abstract_type : Error<
   "allocation of an object of abstract type %0">;
+def err_throw_abstract_type : Error<
+  "cannot throw an object of abstract type %0">;
 
 def err_multiple_final_overriders : Error<
   "virtual function %q0 has more than one final overrider in %1">; 

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=101381&r1=101380&r2=101381&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Thu Apr 15 13:05:39 2010
@@ -411,6 +411,11 @@
                               << E->getSourceRange()))
       return true;
 
+    if (RequireNonAbstractType(ThrowLoc, E->getType(),
+                               PDiag(diag::err_throw_abstract_type)
+                                 << E->getSourceRange()))
+      return true;
+
     // FIXME: This is just a hack to mark the copy constructor referenced.
     // This should go away when the next FIXME is fixed.
     const RecordType *RT = Ty->getAs<RecordType>();

Modified: cfe/trunk/test/SemaCXX/exceptions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/exceptions.cpp?rev=101381&r1=101380&r2=101381&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/exceptions.cpp (original)
+++ cfe/trunk/test/SemaCXX/exceptions.cpp Thu Apr 15 13:05:39 2010
@@ -97,3 +97,13 @@
     }
   }
 }
+
+// Cannot throw an abstract type.
+class foo {
+public:
+  foo() {}
+  void bar () {
+    throw *this; // expected-error{{cannot throw an object of abstract type 'foo'}}
+  }
+  virtual void test () = 0; // expected-note{{pure virtual function 'test'}}
+};





More information about the cfe-commits mailing list