Is this a valid C++ code:
struct S
{
S(S const&) = default;
S(S&) = default;
};
?
Context:
I tried to deal with ambiguity in following code by adding these two lines to S (godbolt):
#include <utility>
struct Inner
{
Inner(int);
};
struct Outer
{
//Outer(Outer const&) = default;
//Outer(Outer&) = default;
template<class T>
Outer(T&& inner) : inner_(std::forward<T>(inner)) {}
Inner inner_;
};
auto foo()
{
auto v1 = Outer(1);
Outer v2 = v1;
return v2.inner_;
}
Uncommenting two lines in S makes GCC happy, but MSVC produces error C2580. Question is -- is MSVC correct or not?
The error for the above S is:
<source>(8): error C2580: 'S::S(S &)': multiple versions of a defaulted special member functions are not allowed