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: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to