Consider the following code:
struct S
{
S(int, double) {}
explicit S(const S&) {}
explicit S(S&&) {}
};
void i_take_an_S(S s) {}
S i_return_an_S() { return S{ 4, 2.0 }; }
int main()
{
i_take_an_S(i_return_an_S());
}
With the '-std=c++17' flag, both g++ and clang++ compile this code just fine. MSVC (with the /std:c++17 flag), however, reports
"error C2664: 'void i_take_an_S(S)': cannot convert argument 1 from 'S' to 'S'"
as a compilation error, with the additional note
"Constructor for struct 'S' is declared 'explicit'".
According to C++17's initialization rules (Explanation of point 3) S
's copy constructor should not be considered for the initialization of the S
parameter of i_take_an_S
; S(int, double)
should rather be selected as an exact match by direct-list-initialization.
Might this be a bug in MSVC?