[LLVMbugs] [Bug 20534] New: ObjC++ attempts to copy lambdas, preventing capture of move-only types
    bugzilla-daemon at llvm.org 
    bugzilla-daemon at llvm.org
       
    Mon Aug  4 14:18:56 PDT 2014
    
    
  
http://llvm.org/bugs/show_bug.cgi?id=20534
            Bug ID: 20534
           Summary: ObjC++ attempts to copy lambdas, preventing capture of
                    move-only types
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++1y
          Assignee: unassignedclangbugs at nondot.org
          Reporter: vlovich at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified
ObjC++ supports capturing move-only types as x-values if they are in __block
storage.  However, if C++14 lambdas are used, it is not possible to capture
move-only types, even though there would be a strong motivation for such.  
I'm not sure about the internals of how the conversion of C++ lambda to ObjC
block is done, but perhaps lambdas can also be treated as x-values as well when
being converted?
GCD Example:
Preferred syntax:
void logMessage(std::unique_ptr<LogData> logData)
{
    dispatch_async([logData = logData] {
        // process logData
    });
}
fails due to attempt to copy lambda (presumably into ObjC block).
Workaround syntax:
void logMessage(std::unique_ptr<LogData> logDataArg)
{
    __block auto logData = std::move(logDataArg);
    dispatch_async(^{
        // process logData
    });
}
Of course this has several properties that are not ideal given the desired
syntax:
1: More verbose
2: All argument variables have to be copied into a local __block storage
variable manually (typos are easy).
3: Explicit capture semantics of C++ lambas are unavailable.
-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140804/e78724bf/attachment.html>
    
    
More information about the llvm-bugs
mailing list