]> granicus.if.org Git - clang/commitdiff
Diagnose by-copy captures of abstract classes.
authorDouglas Gregor <dgregor@apple.com>
Fri, 11 Oct 2013 04:25:21 +0000 (04:25 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 11 Oct 2013 04:25:21 +0000 (04:25 +0000)
Fixes <rdar://problem/14468891>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192419 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaExpr.cpp
test/CXX/expr/expr.prim/expr.prim.lambda/p14.cpp

index 88ced4c7edd84332a8345964182dae18a0a58d45..670ff9c918ce0cc922b6e810f0448c1e1d3b5db9 100644 (file)
@@ -922,6 +922,8 @@ def err_allocation_of_abstract_type : Error<
 def err_throw_abstract_type : Error<
   "cannot throw an object of abstract type %0">;
 def err_array_of_abstract_type : Error<"array of abstract class type %0">;
+def err_capture_of_abstract_type : Error<
+  "by-copy capture of value of abstract type %0">;
 
 def err_multiple_final_overriders : Error<
   "virtual function %q0 has more than one final overrider in %1">; 
index 690661df1c7de5c703c651b9d37e2ea8f4f2b1c9..6bcc49ed6236b4d210d768d88e015bd2772e1ff4 100644 (file)
@@ -11687,6 +11687,10 @@ static bool captureInLambda(LambdaScopeInfo *LSI,
       }
       return false;
     }
+
+    if (S.RequireNonAbstractType(Loc, CaptureType,
+                                 diag::err_capture_of_abstract_type))
+      return false;
   }
 
   // Capture this variable in the lambda.
index 6358215a55594ff04bb14eefbd4dbcbf5a64a679..2ddcf18409e98ee7d636ee731d44f1bf986377ac 100644 (file)
@@ -88,3 +88,15 @@ struct CaptureArrayAndThis {
   }
 };
 
+namespace rdar14468891 {
+  class X {
+  public:
+    virtual ~X() = 0; // expected-note{{unimplemented pure virtual method '~X' in 'X'}}
+  };
+
+  class Y : public X { };
+
+  void capture(X &x) {
+    [x]() {}(); // expected-error{{by-copy capture of value of abstract type 'rdar14468891::X'}}
+  }
+}