https://llvm.org/bugs/show_bug.cgi?id=26899
Bug ID: 26899 Summary: Valarray constructor should have the elements of the array value-initialized as of C++14 standard, but they are initialized using a copy constructor. Product: libc++ Version: 3.8 Hardware: PC OS: Linux Status: NEW Severity: normal Priority: P Component: All Bugs Assignee: unassignedclangb...@nondot.org Reporter: ionelpopesc...@yahoo.com CC: llvm-bugs@lists.llvm.org, mclow.li...@gmail.com Classification: Unclassified The behavior of the valarray constructor is different from the decription in the c++14 standard. It says that the elements of the array are value-initialized but the instead just only one element is value-initialized and the rest are initialized using a copy constructor. Decription in the c++14 standard: explicit valarray(size_t); 2 The array created by this constructor has a length equal to the value of the argument. The elements of the array are value-initialized Example: #include <stdio.h> #include <valarray> int id =0; struct Foo { Foo() { printf("Spawn Foo ID %d \n", id++); } }; int main() { std::valarray<Foo> x(5); } Results: If we use Intel compiler (Icc 2016) or VS2015, gcc 4.9.2 Spawn Foo ID 0 Spawn Foo ID 1 Spawn Foo ID 2 Spawn Foo ID 3 Spawn Foo ID 4 If we use clang++ and libc++ We get the following output Spawn Foo ID 0 Spawn Foo ID 1 There are only two appearances because the copy constructor is called instead of the default constructor as it should be for value initialization. -- You are receiving this mail because: You are on the CC list for the bug.
_______________________________________________ llvm-bugs mailing list llvm-bugs@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs