title: To what extent is C++ a statically-typed language?
body: <p>I used to think that the answer to this question was "<em>100%</em>", but I've recently been pointed to an example that makes it worth thinking twice. Consider a C array declared as an object with automatic storage duration:</p>
  
  <pre><code>int main()
  {
      int foo[42] = { 0 };
  }
  </code></pre>
  
  <p>Here, the type of <code>foo</code> is clearly <code>int[42]</code>. Consider, instead, this case:</p>
  
  <pre><code>int main()
  {
      int* foo = new int[rand() % 42];
      delete[] foo;
  }
  </code></pre>
  
  <p>Here, the type of <code>foo</code> is <code>int*</code>, but how can one tell the type of the <strong>object created by the <code>new</code> expression</strong> at compile-time? (Emphasis is meant to stress the fact that I am not talking about the pointer returned by the <code>new</code> expression, but rather about the <em>array object</em> created by the <code>new</code> expression).</p>
  
  <p>This is what Paragraph 5.3.4/1 of the C++11 Standard specifies about the result of a <code>new</code> expression:</p>
  
  <blockquote>
    <p>[...] Entities created by a <em>new-expression</em> have dynamic storage duration (3.7.4). [ Note: the lifetime of such
    an entity is not necessarily restricted to the scope in which it is created. —end note ] If the entity is a non-array
    object, the <em>new-expression</em> returns a pointer to the object created. If it is an array, the <em>new-expression</em>
    returns a pointer to the initial element of the array.</p>
  </blockquote>
  
  <p>I used to think that in C++ the type of all objects is determined at compile-time, but the above example seems to disprove that belief. Also, per Paragraph 1.8/1:</p>
  
  <blockquote>
    <p>[...] The properties of an object are determined <strong>when the object
    is created</strong>. An object can have a name (Clause 3). An object has a storage duration (3.7) which influences
    its lifetime (3.8). An object has a type (3.9). [...]</p>
  </blockquote>
  
  <p>So my questions are:</p>
  
  <ol>
  <li>What is meant by "<em>properties</em>" in the last quoted paragraph? Clearly, the name of an object cannot count as something which is determined "<em>when the object is created</em>"- unless "<em>created</em>" here means something different than I think;</li>
  <li>Are there other examples of objects whose type is determined only at run-time?</li>
  <li>To what extent is it correct to say that C++ is a statically-typed language? Or rather, what is the most proper way of classifying C++ in this respect?</li>
  </ol>
  
  <p>It would be great if anybody could elaborate at least on one of the above points.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>The Standard seems to make it clear that the <code>new</code> expression does indeed create an <strong>array object</strong>, and not just several objects laid out as an array as pointed out by some. Per Paragraph 5.3.4/5 (courtesy of <a href="https://stackoverflow.com/users/500104/xeo">Xeo</a>):</p>
  
  <blockquote>
    <p><strong>When the allocated object is an array</strong> (that is, the <em>noptr-new-declarator</em> syntax is used or the <em>new-type-id</em> or
    <em>type-id</em> denotes an array type), the new-expression yields a pointer to the initial element (if any) of the array.
    [ Note: both <code>new int</code> and <code>new int[10]</code> have type <code>int*</code> and the type of <code>new int[i][10]</code> is <code>int (*)[10]</code>
    —end note ] The <em>attribute-specifier-seq</em> in a <em>noptr-new-declarator</em> appertains <strong>to the associated array type</strong>.</p>
  </blockquote>