<div dir="ltr">Hi All,<div>I was going through a gcc TC for C++11. The test case is as follows -</div><div><br></div><div><div>// { dg-options -std=c++0x }</div><div>// { dg-do run }</div><div><br></div><div>extern "C" void abort ();</div>
<div>extern int ar[2];</div><div><br></div><div>int f()</div><div>{</div><div>  int k = 0;</div><div>  if (ar[0] != 42 || ar[1] != 0)</div><div>    abort();</div><div>  return 1;</div><div>}</div><div><br></div><div>int i = f();</div>
<div><br></div><div>int ar[2] = {42,i};</div><div><br></div><div>int main()</div><div>{ </div><div>  return 0;</div><div>}</div></div><div><br></div><div>During dynamic initialization of i in function f() the value of ar[0] is 0 in case of clang were as in case of gcc it is 42.</div>
<div><br></div><div>As per standard(section 3.6.2) all global values should initially be zero initialized followed by const initialized if possible before dynamic initialization takes place.</div><div>Hence as per standard the const initialization of int ar[2] = {42,i}; should fail as i is not a const here( which seems to be happening in clang). Hence ar[0],ar[1] is still zero initialized because of which during dynamic initialization in f() ar[0]  is 0 which seems to be the correct behavior.</div>
<div><br></div><div>Can i conclude here that clang is behaving correctly and the tc is wrong? or am i missing something which this gcc tc wanted to capture?</div><div><br></div><div>Thanks</div></div>