]> granicus.if.org Git - clang/commitdiff
Diagnose attempts to throw an abstract class type.
authorDouglas Gregor <dgregor@apple.com>
Thu, 15 Apr 2010 18:05:39 +0000 (18:05 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 15 Apr 2010 18:05:39 +0000 (18:05 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101381 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaExprCXX.cpp
test/SemaCXX/exceptions.cpp

index cb45f66cd87ee99135e8890f06d08f32cfb04950..7b1b2f496ae7e8d1a16350da44ed1eed62de5fc5 100644 (file)
@@ -402,6 +402,8 @@ def err_abstract_type_in_decl : Error<
   "%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">; 
index 04b3d83f3e31d780d75f005dc1402c9771511070..be3ef83d9944c842f1c3cacaccfbc655f010c27b 100644 (file)
@@ -411,6 +411,11 @@ bool Sema::CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *&E) {
                               << 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>();
index 2ed4bfe885623ac5ffe7e0be9ab9ca033880ae59..e009558ce3e7f72cf7f4a44fa11908757d16a3bd 100644 (file)
@@ -97,3 +97,13 @@ BadReturn::BadReturn(int) try {
     }
   }
 }
+
+// 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'}}
+};