diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -1913,6 +1913,11 @@ return; } case TEK_Aggregate: + if (capturedByInit) { + // TODO: how can we delay here if D is captured by its initializer? + CGM.ErrorUnsupported( + init, "aggregate initialized with potentially self-capturing block"); + } if (type->isAtomicType()) { EmitAtomicInit(const_cast(init), lvalue); } else { @@ -1921,7 +1926,6 @@ Overlap = AggValueSlot::DoesNotOverlap; else if (auto *FD = dyn_cast(D)) Overlap = getOverlapForFieldInit(FD); - // TODO: how can we delay here if D is captured by its initializer? EmitAggExpr(init, AggValueSlot::forLValue( lvalue, *this, AggValueSlot::IsDestructed, AggValueSlot::DoesNotNeedGCBarriers, diff --git a/clang/test/CodeGenCXX/block-capture-own-init.cpp b/clang/test/CodeGenCXX/block-capture-own-init.cpp new file mode 100644 --- /dev/null +++ b/clang/test/CodeGenCXX/block-capture-own-init.cpp @@ -0,0 +1,9 @@ +// RUN: not %clang_cc1 -x c++ -std=c++11 -fblocks -emit-llvm %s 2>&1 | FileCheck %s + +void test_aggregate_captured_by_own_init() { + struct foo { int a[100]; }; + extern foo get_foo(foo *(^)()); + // CHECK: error: cannot compile this aggregate initialized with potentially self-capturing block yet + __block foo f = get_foo(^{ return &f; }); +} +