title: C++ self-referencing array?
body: <p>I accidentally created a bug in a program by self-referencing in an array. Here's a very simplified demo program similar in concept:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int kTest[] = {
      kTest[0]
  };
  
  int main() {
      cout &lt;&lt; kTest[0] &lt;&lt; endl;
  }
  </code></pre>
  
  <p>I was surprised that I received neither a compiler error or even a warning on this code! In my case it ended up producing unpredictable output. Is it accessing garbage memory?</p>
  
  <p>I was curious about under what circumstances this would have well-defined output (if ever!). </p>
  
  <p><strong>Edit</strong>: Does it make a difference if <code>kTest</code> is <code>static</code>? What about <code>const</code>? Both?</p>