Note that there are some explanatory texts on larger screens.

plurals
  1. POExplicit Type Conversion and Multiple Simple Type Specifiers
    text
    copied!<p>To value initialize an object of type <code>T</code>, one would do something along the lines of one of the following:</p> <pre><code>T x = T(); T x((T())); </code></pre> <p>My question concerns types specified by a combination of simple type specifiers, e.g., <code>unsigned int</code>:</p> <pre><code>unsigned int x = unsigned int(); unsigned int x((unsigned int())); </code></pre> <p>Visual C++ 2008 and Intel C++ Compiler 11.1 accept both of these without warnings; Comeau 4.3.10.1b2 and g++ 3.4.5 (which is, admittedly, not particularly recent) do not.</p> <p>According to the C++ standard (C++03 5.2.3/2, expr.type.conv):</p> <blockquote> <p>The expression <code>T()</code>, where <code>T</code> is a simple-type-specifier (7.1.5.2) for a non-array complete object type or the (possibly cv-qualified) <code>void</code> type, creates an rvalue of the specified type, which is value-initialized</p> </blockquote> <p>7.1.5.2 says, "the simple type specifiers are," and follows with a list that includes <code>unsigned</code> and <code>int</code>. </p> <p>Therefore, given that in 5.2.3/2, "simple-type-specifier" is singular, and <code>unsigned</code> and <code>int</code> are two type specifiers, are the examples above that use <code>unsigned int</code> invalid? (and, if so, the followup is, is it incorrect for Microsoft and Intel to support said expressions?)</p> <p>This question is more out of curiosity than anything else; for all of the types specified by a combination of multiple simple type specifiers, value initialization is equivalent to zero initialization. (This question was prompted by <a href="https://stackoverflow.com/questions/2143022/how-to-correctly-initialize-variable-of-template-type/2143038#2143038">comments in response to this answer to a question about initialization</a>).</p>
 

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