Open tiagomacarios opened 6 months ago
The move ctor of S
is defaulted and implicitly deleted. Per [over.match.funcs.general]/9, it is ignored in overload resolution. However, it seems better to figure it out in diagnostic message.
Currently, Clang is seemingly considering invalid conversion sequence.
struct M {
M();
M(M&);
};
struct S;
struct T {
T() = default;
T(const S&); // make lvalue of S convertible to T
};
struct S {
T m1;
M m2;
};
S fun() {
S s{};
return s; // Clang considers this well-formed in C++23 given S& is convertible to T. NRVO enabled.
}
struct M {
M();
M(M&);
};
struct S;
struct T {
T() = default;
T(const S&);
};
struct S {
T m1;
M m2;
};
S fun() {
S s{};
return static_cast<S&&>(s); // Clang considers this well-formed since C++20!
}
Perhaps Clang overly generalizes the change in P0960R3 to the copy-initialization in return statements. Per CWG2824, aggregate initialization shouldn't be considered in these contexts.
@llvm/issue-subscribers-clang-frontend
Author: Tiago (tiagomacarios)
The diagnostics for the following code are very poor: https://godbolt.org/z/5nv9dcr14
clang's output:
gcc's output: