<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="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."
   href="https://llvm.org/bugs/show_bug.cgi?id=26899">26899</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Valarray constructor should have the elements of the array value-initialized as of C++14 standard, but they are initialized using a copy constructor.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.8
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>ionelpopescu97@yahoo.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>