I have a template class Property, that wraps around other types:
template <typename T>
class Property
{
private:
T value;
public:
Property() = default;
Property(const T& initialValue)
: value(initialValue) {}
virtual ~Property() = default;
//Make this class non-copyable.
Property(const Property&) = delete;
Property& operator=(const Property&) = delete;
virtual Property& operator=(const T& other)
{
value = other;
return *this;
}
//... a bunch of other unimportant stuff
}
Visual Studio 15.7.6 and a few other compilers are perfectly happy with
{ //function or class definition (default member initialization)
Property<int> prop = 5;
}
However, (a slightly modified for proprietary compilation target) GCC 4.9.4 fails on the above declaration:
Error GD4849D22 use of deleted function
'Property<T>::Property(const Property<T>&) [with T = int]'
It appears the compiler is attempting to construct a RValue Property and then use the deleted copy constructor instead of simply using the type appropriate constructor.
Is this a case of GCC being over cautious?
Property<int> prop(5); //explicit constructor call - valid with GCC Compiler
Property<int> myOtherProp;
myOtherProp = 5; //Also fine (obviously)
Or is it a case of MSVC playing fast and loose and doing something the standard says it shouldn't or doesn't have to?
Unfortunately I cant update my GCC version. Because the workaround exists I'm looking more for the "why" this happens than anything else.