[PATCH] D58164: Block+lambda: allow reference capture

JF Bastien via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 13 15:07:29 PST 2019


jfb updated this revision to Diff 186752.
jfb added a comment.

- Check for references when looking for copyexpr directly.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58164/new/

https://reviews.llvm.org/D58164

Files:
  lib/CodeGen/CGBlocks.cpp
  test/CodeGenCXX/lambda-capturing-block.cpp


Index: test/CodeGenCXX/lambda-capturing-block.cpp
===================================================================
--- /dev/null
+++ test/CodeGenCXX/lambda-capturing-block.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -triple=x86_64-apple-darwin -S -emit-llvm -std=c++17 -fblocks -fcxx-exceptions -o - %s | FileCheck %s
+
+extern "C" {
+
+struct derp {
+    derp() {}
+    derp(const derp& _Src) {}
+    derp(derp&& _Src) {}
+    ~derp() {}
+    void cancel() const{}
+};
+
+// CHECK-LABEL: test(
+void test() {
+  derp c;	
+  auto b = [&](auto const& func) noexcept {
+    auto block = ^() {
+      try {
+        func();
+      } catch (...) {
+        c.cancel();
+      }
+    };
+    block();
+  };
+	
+  b([](){});
+}
+
+}
Index: lib/CodeGen/CGBlocks.cpp
===================================================================
--- lib/CodeGen/CGBlocks.cpp
+++ lib/CodeGen/CGBlocks.cpp
@@ -622,7 +622,7 @@
       }
 
     // So do types that require non-trivial copy construction.
-    } else if (CI.hasCopyExpr()) {
+    } else if (CI.hasCopyExpr() && VT->getAsCXXRecordDecl()) {
       info.NeedsCopyDispose = true;
       info.HasCXXObject = true;
       if (!VT->getAsCXXRecordDecl()->isExternallyVisible())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58164.186752.patch
Type: text/x-patch
Size: 1211 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190213/1d177efe/attachment.bin>


More information about the cfe-commits mailing list