From: Douglas Gregor Date: Fri, 11 Oct 2013 04:25:21 +0000 (+0000) Subject: Diagnose by-copy captures of abstract classes. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=730a2c2f915d81f6cdb53918d8b155ee25b8175f;p=clang Diagnose by-copy captures of abstract classes. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192419 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 88ced4c7ed..670ff9c918 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -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">; diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 690661df1c..6bcc49ed62 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -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. diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p14.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p14.cpp index 6358215a55..2ddcf18409 100644 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/p14.cpp +++ b/test/CXX/expr/expr.prim/expr.prim.lambda/p14.cpp @@ -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'}} + } +}