Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compiler/C++/Front End/Initialization    [ Add a report in this area ]  
Report #:  83751   Status: Closed
Value-initialization: arrays should have each element value-initialized
Project:  C++Builder Build #:  6.21.3615.26516
Version:    14.0 Submitted By:   Niels Dekker
Report Type:  Basic functionality failure Date Reported:  4/11/2010 7:54:33 AM
Severity:    Serious / Highly visible problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All platforms Internal Tracking #:   275893
Resolution: Fixed (Resolution Comments) Resolved in Build: : 15.0.3860.33047
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: 10
Description
Thanks for fixing issue 51854, "Value-initialization: POD struct should be zero-initialized", http://qc.embarcadero.com/wc/qcmain.aspx?d=51854 I can confirm that I'm no longer able reproduce the bug, using the latest version of your compiler (Embarcadero C++ 6.21, 2010).

However, your compiler appears to have a similar problem with regard to built-in arrays. The C++ Standard (2003) says that to value-initialize an array means that each element is value-initialized ([dcl.init]). However, when I try to value-initialize an array, the compiler gives me a warning instead: "W8039 Constructor initializer list ignored".  And when I do so for an array of integers, they remain uninitialized. (Or at least, they remain non-zero.) When I run the program presented in "Steps to Reproduce", it halts at the first assert, saying "Assertion failed: wrapper.data[0] == 0"

Please fix it!
Steps to Reproduce:
#include <cassert>

  struct TWrapper {
    int data[2];
    TWrapper() : data() {}
  };

  int main() {
    TWrapper wrapper;
    // Asserts should not fail, but they do!
    assert(wrapper.data[0] == 0);
    assert(wrapper.data[1] == 0);

    // Should return zero, but it does not.
    return wrapper.data[0] + wrapper.data[1];
  }
Workarounds
As a workaround, people could use boost::value_initialized<T[N]>, from Fernando Cacciola: http://www.boost.org/libs/utility/value_init.htm

But of course, it would be preferable to get value-initialization "out of the box", straight from the compiler.
Attachment
None
Comments

Tomohiro Takahashi at 4/11/2010 7:37:47 PM -
I confrmed your issue. I will open this report after maintenance of internal tracking system.
Thanks.

Niels Dekker at 4/12/2010 12:37:58 PM -
Thanks for your reply, Tomohiro. For your information, I just wrote a test which verifies the implementation of value-initialization for an large number of types, including arrays, classes, structs and unions. The test is to be included with Boost version 1.44.0, but a preliminary version is already at https://svn.boost.org/svn/boost/trunk/libs/config/test/boost_no_com_value_init.ipp  

While the file will become part of the Boost Config component, it can also be used without having Boost installed. (It does not depend on any other Boost file.) For example, by including the file in a little console application:

  //////////////////////////////////////////////////
  #include "boost_no_com_value_init.ipp"
  #include <cassert>

  int main() {
    const int num_failures =
      boost_no_complete_value_initialization::test();
    assert(num_failures == 0);
    return num_failures;
  }
  //////////////////////////////////////////////////

Please tell me if you have any comment, remark or suggestion regarding this test.

Server Response from: ETNACODE01