P
powerchord
Guest
In Visual Studio Professional 2013 Update 4 the following code compiles without errors:
class Foo
{
std::vector<int> v = 666;
};
Why? I dont understand it. 666 is an int. An int cannot be converted to std::vector because there is no matching converting constructor (the candidate std::vector::vector(size_type) does not match because its declared explicit). Is this not true? Even IntelliSense complains:
IntelliSense: no suitable constructor exists to convert from "int" to "std::vector<int, std::allocator<int>>"
At run-time this code eventually calls std::vector::vector(size_type) with 666. How can that be? Is this really correct? If so then non-static data member initialization must be somehow different from "normal" initialization because std::vector<int> v = 666; in a function or at global or namespace scope (correctly) yields the following error:
error C2440: initializing : cannot convert from int to std::vector<int,std::allocator<_Ty>>
I already posted this as a bug twice:
https://connect.microsoft.com/VisualStudio/feedback/details/956918/bug-in-visual-c-compiler-nov-2013-ctp-with-non-static-data-member-braced-init-list-initialization
https://connect.microsoft.com/VisualStudio/feedback/details/970093/explicit-ctor-vector-vector-size-type-implicitly-called-by-the-compiler
It was finally closed as fixed. But its still present. Please tell me why.
Or is this not a bug?
Continue reading...
class Foo
{
std::vector<int> v = 666;
};
Why? I dont understand it. 666 is an int. An int cannot be converted to std::vector because there is no matching converting constructor (the candidate std::vector::vector(size_type) does not match because its declared explicit). Is this not true? Even IntelliSense complains:
IntelliSense: no suitable constructor exists to convert from "int" to "std::vector<int, std::allocator<int>>"
At run-time this code eventually calls std::vector::vector(size_type) with 666. How can that be? Is this really correct? If so then non-static data member initialization must be somehow different from "normal" initialization because std::vector<int> v = 666; in a function or at global or namespace scope (correctly) yields the following error:
error C2440: initializing : cannot convert from int to std::vector<int,std::allocator<_Ty>>
I already posted this as a bug twice:
https://connect.microsoft.com/VisualStudio/feedback/details/956918/bug-in-visual-c-compiler-nov-2013-ctp-with-non-static-data-member-braced-init-list-initialization
https://connect.microsoft.com/VisualStudio/feedback/details/970093/explicit-ctor-vector-vector-size-type-implicitly-called-by-the-compiler
It was finally closed as fixed. But its still present. Please tell me why.
Or is this not a bug?
Continue reading...