While testing the VS2015 C++ compiler I stumbled upon a strange bug with the default
keyword. If I do:
struct Dummy
{
Dummy() = default;
Dummy(const Dummy &) = delete;
};
int main()
{
const Dummy& ref = Dummy();
return 0;
}
I get
error C2280: 'Dummy::Dummy(const Dummy &)': attempting to reference a deleted function
note: see declaration of 'Dummy::Dummy'
But if I use an empty constructor
struct Dummy
{
Dummy() {}
Dummy(const Dummy &) = delete;
};
int main()
{
const Dummy& ref = Dummy();
return 0;
}
The code compiles. Running the first example with g++ or clang produces no error.
Why would using the default constructor with VS2015 try to use the copy constructor where it doesn't in g++ or clang?