r192419 - Diagnose by-copy captures of abstract classes.
Douglas Gregor
dgregor at apple.com
Thu Oct 10 21:25:22 PDT 2013
Author: dgregor
Date: Thu Oct 10 23:25:21 2013
New Revision: 192419
URL: http://llvm.org/viewvc/llvm-project?rev=192419&view=rev
Log:
Diagnose by-copy captures of abstract classes.
Fixes <rdar://problem/14468891>.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p14.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=192419&r1=192418&r2=192419&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Oct 10 23:25:21 2013
@@ -922,6 +922,8 @@ def err_allocation_of_abstract_type : Er
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">;
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=192419&r1=192418&r2=192419&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Oct 10 23:25:21 2013
@@ -11687,6 +11687,10 @@ static bool captureInLambda(LambdaScopeI
}
return false;
}
+
+ if (S.RequireNonAbstractType(Loc, CaptureType,
+ diag::err_capture_of_abstract_type))
+ return false;
}
// Capture this variable in the lambda.
Modified: cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p14.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p14.cpp?rev=192419&r1=192418&r2=192419&view=diff
==============================================================================
--- cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p14.cpp (original)
+++ cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p14.cpp Thu Oct 10 23:25:21 2013
@@ -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'}}
+ }
+}
More information about the cfe-commits
mailing list