https://llvm.org/bugs/show_bug.cgi?id=31071
Bug ID: 31071
Summary: Cannot assign a lambda expression to an
optional<function<...>>
Product: clang
Version: unspecified
Hardware: Macintosh
OS: MacOS X
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected]
Classification: Unclassified
Created attachment 17615
--> https://llvm.org/bugs/attachment.cgi?id=17615&action=edit
Sample project
Suppose we a function that takes a completion handler in the form of an
optional<function>:
using Handler = function<void(void)>;
void doSomething(int flags, optional<Handler> callback =
optional<Handler>()) {
if (callback) {
(*callback)();
}
}
Since a default value of an empty optional is provided, I can invoke this
without passing a value for the final parameter just fine:
doSomething(0);
Moreover, I can invoke `doSomething` if I explicitly cast a lambda expression
to a `Handler` and pass it for the final parameter:
doSomething(0, Handler([]{
cout << "hello world" << endl;
}));
However, passing a lambda expression directly does not work (the following does
not compile with "No matching function for call to 'doSomething'"):
doSomething(0, []{
cout << "hello world" << endl;
});
I assume this is because the type checker doesn't know we can assign a lambda
expression to an optional (even if it's an optional<function> and lambda
expression can be assigned to functions).
In other words, if a lambda expression L can be assigned to a function F, we
should be able to assign L to an optional of type optional<F>.
A sample project that demonstrates this is attached. I am testing with Xcode
8.1 GM.
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs