title: Should the "optimized out" value be a random or not?
body: <p>I want to check how optimization options of <code>gcc</code> to affect the program, and the code is like this:  </p>
  
  <pre><code>#include &lt;iostream&gt;
  
  class A {
  public:
          A() {
                  a[0] = 10;
                  a[1] = 20;
                  empty;
          }
          int a[5];
          bool empty;
  };
  
  int main(void){
          A a;
  
          std::cout &lt;&lt; a.empty &lt;&lt; std::endl;
          return 0;
  }
  </code></pre>
  
  <p>Since <code>empty</code> member isn't assigned value in constructor, I expect it is a random value. Compile and run it:  </p>
  
  <pre><code># g++ -g test.cpp
  # ./a.out
  254
  # ./a.out
  254
  # ./a.out
  253
  # ./a.out
  253
  </code></pre>
  
  <p>The result is as my expected. Then I use <code>-O2</code> compile option:  </p>
  
  <pre><code># g++ -g -O2 test.cpp
  # ./a.out
  0
  # ./a.out
  0
  # ./a.out
  0
  # ./a.out
  0
  </code></pre>
  
  <p>It seems always <code>0</code>. I use <code>gdb</code> to debug the program:  </p>
  
  <pre><code>14      int main(void){
  (gdb) n
  17                      std::cout &lt;&lt; a.empty &lt;&lt; std::endl;
  (gdb) p a
  $1 = {
    a = {[0] = 10, [1] = 20, [2] = &lt;optimized out&gt;, [3] = &lt;optimized out&gt;, [4] = &lt;optimized out&gt;},
    empty = &lt;optimized out&gt;
  }
  </code></pre>
  
  <p>I just want to make sure since the <code>empty</code> is <code>optimized out</code>, its value should also be random, is it right?</p>