[llvm-bugs] [Bug 26899] New: Valarray constructor should have the elements of the array value-initialized as of C++14 standard, but they are initialized using a copy constructor.

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Mar 10 07:54:07 PST 2016


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: unassignedclangbugs at nondot.org
          Reporter: ionelpopescu97 at yahoo.com
                CC: llvm-bugs at lists.llvm.org, mclow.lists at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160310/0488528f/attachment.html>


More information about the llvm-bugs mailing list