Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Update:</strong> Thanks to Faisal Vali and Richard Smith, this bug has been corrected in Clang ToT; see the <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx11-initializer-array-new.cpp?revision=196995&amp;view=markup&amp;pathrev=196995">test file</a> introduced by the commit.</p> <hr> <p>According to <strong>§8.5.1 [dcl.init.aggr]</strong> it appears that Clang is wrong:</p> <blockquote> <p>11/ Braces can be elided in an <em>initializer-list</em> as follows. If the <em>initializer-list</em> begins with a left brace, then the succeeding comma-separated list of <em>initializer-clauses</em> initializes the members of a subaggregate; it is erroneous for there to be more <em>initializer-clauses</em> than members. If, however, the <em>initializer-list</em> for a subaggregate does not begin with a left brace, then only enough <em>initializer-clauses</em> from the list are taken to initialize the members of the subaggregate; any remaining <em>initializer-clauses</em> are left to initialize the next member of the aggregate of which the current subaggregate is a member. [ <em>Example:</em></p> <pre><code>float y[4][3] = { { 1, 3, 5 }, { 2, 4, 6 }, { 3, 5, 7 }, }; </code></pre> <p>is a completely-braced initialization: 1, 3, and 5 initialize the first row of the array <code>y[0]</code>, namely <code>y[0][0]</code>, <code>y[0][1]</code>, and <code>y[0][2]</code>. Likewise the next two lines initialize <code>y[1]</code> and <code>y[2]</code>. The initializer ends early and therefore <code>y[3]</code>s elements are initialized as if explicitly initialized with an expression of the form <code>float()</code>, that is, are initialized with <code>0.0</code>. In the following example, braces in the <em>initializer-list</em> are elided; however the <em>initializer-list</em> has the same effect as the completely-braced <em>initializer-list</em> of the above example,</p> <pre><code>float y[4][3] = { 1, 3, 5, 2, 4, 6, 3, 5, 7 }; </code></pre> <p>The initializer for y begins with a left brace, but the one for <code>y[0]</code> does not, therefore three elements from the list are used. Likewise the next three are taken successively for <code>y[1]</code> and <code>y[2]</code>. —<em>end example</em> ]</p> </blockquote> <p>Which I think applies because of <strong>§5.3.4 [expr.new]</strong>:</p> <blockquote> <p>15/ A <em>new-expression</em> that creates an object of type T initializes that object as follows:</p> <ul> <li>If the <em>new-initializer</em> is omitted, the object is default-initialized (<strong>§8.5</strong>); if no initialization is performed, the object has indeterminate value.</li> <li>Otherwise, the <em>new-initializer</em> is interpreted according to the initialization rules of <strong>§8.5</strong> for direct initialization.</li> </ul> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload