Open
Description
In the C++20 program below, the lambda has a non-static member operator(), but its object parameter is skipped when looking for a promise constructor overload. This results in the first overload being called, and an output of Wrong
.
Tested on 18.1.5 and 19.0.0git (b5af667). When compiled with GCC or MSVC, the output is Correct
, as expected.
Additionally, removing the second constructor should make the resulting program no longer compile, which is the case with MSVC and GCC, but not Clang.
#include <coroutine>
#include <iostream>
struct coro {};
struct promise {
promise(int) {std::cout << "Wrong\n";}
promise(auto, int){std::cout << "Correct\n";} // Remove me for an additional test case!
coro get_return_object() {return {};}
std::suspend_never initial_suspend() {return {};}
std::suspend_never final_suspend() noexcept {return {};}
void return_value(int) {}
void unhandled_exception() {}
};
template<typename... T>
struct std::coroutine_traits<coro, T...> {
using promise_type = promise;
};
int main() {
int x = 0;
[x](int y) -> coro { co_return x + y; }(1);
}
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
No status