Thanks Eli, Karen for the clarification.<br><br>On Saturday, September 28, 2013, Karen Shaeffer <<a href="mailto:shaeffer@neuralscape.com">shaeffer@neuralscape.com</a>> wrote:<br>> On Thu, Sep 26, 2013 at 09:49:27AM +0530, Karthik Bhat wrote:<br>
>> Also i think standard section 3.6.2 point 2 mentions as -<br>>><br>>> Constant initialization is performed:<br>>> — *if each full-expression (including implicit conversions) that appears in<br>>> the initializer of a reference with*<br>
>> *static or thread storage duration is a constant expression* (5.19) and the<br>>> reference is bound to an lvalue<br>>> designating an object with static storage duration or to a temporary (see<br>>> 12.2);<br>
>><br>>> since i here is not const expression the point each full-expression that<br>>> appears in the initializer fails in this tc and hence a[0] need not be<br>>> const initialized to 42.<br>>> Am i right?<br>
>><br>>> Thanks!<br>><br>> Hi Karthik,<br>><br>> I believe you cannot use a rule that must be satisfied in 3.6.2 note 2 to invalidate<br>> the use of note 3 exception. If you get to note 3, it is a precondition that you already<br>
> failed to satisfy the conditions set forth in note 2. Note 3 presents a different set<br>> of conditions, that if satisfied, give the implementation the option to ignore the failure<br>> in note 2 requirements.<br>
><br>> While you point to a statement that is clearly related to the all or nothing initialization<br>> of containers or classes, that all or nothing rule is associated with the objects themselves<br>> outside of the scope of 3.6.2 note 2. I believe that is what is needed to invalidate the use<br>
> of 3.6.2 note 3 exception - a general rule associated with the objects outside the scope of<br>> note 2.<br>><br>> I wanted to thank you for sharing the test case. Interesting and informative.<br>><br>> enjoy,<br>
> Karen<br>> --<br>> Karen Shaeffer                 Be aware: If you see an obstacle in your path,<br>> Neuralscape Services           that obstacle is your path.        Zen proverb<br>><br>>><br>>><br>
>> On Thu, Sep 26, 2013 at 9:40 AM, Eli Friedman <<a href="mailto:eli.friedman@gmail.com">eli.friedman@gmail.com</a>>wrote:<br>>><br>>> > On Wed, Sep 25, 2013 at 8:12 PM, Karen Shaeffer <<a href="mailto:shaeffer@neuralscape.com">shaeffer@neuralscape.com</a>>wrote:<br>
>> ><br>>> >> On Wed, Sep 25, 2013 at 03:08:06PM -0700, Eli Friedman wrote:<br>>> >> > On Wed, Sep 25, 2013 at 3:02 PM, Karen Shaeffer <<br>>> >> <a href="mailto:shaeffer@neuralscape.com">shaeffer@neuralscape.com</a>>wrote:<br>
>> >> ><br>>> >> > > On Wed, Sep 25, 2013 at 02:40:37PM -0700, Eli Friedman wrote:<br>>> >> > > > On Wed, Sep 25, 2013 at 4:49 AM, Karthik Bhat <<br>>> >> > > <a href="mailto:blitz.opensource@gmail.com">blitz.opensource@gmail.com</a>>wrote:<br>
>> >> > > ><br>>> >> > > > > Hi All,<br>>> >> > > > > I was going through a gcc TC for C++11. The test case is as<br>>> >> follows -<br>>> >> > > > ><br>
>> >> > > > > // { dg-options -std=c++0x }<br>>> >> > > > > // { dg-do run }<br>>> >> > > > ><br>>> >> > > > > extern "C" void abort ();<br>
>> >> > > > > extern int ar[2];<br>>> >> > > > ><br>>> >> > > > > int f()<br>>> >> > > > > {<br>>> >> > > > >   int k = 0;<br>
>> >> > > > >   if (ar[0] != 42 || ar[1] != 0)<br>>> >> > > > >     abort();<br>>> >> > > > >   return 1;<br>>> >> > > > > }<br>
>> >> > > > ><br>>> >> > > > > int i = f();<br>>> >> > > > ><br>>> >> > > > > int ar[2] = {42,i};<br>>> >> > > > ><br>
>> >> > > > > int main()<br>>> >> > > > > {<br>>> >> > > > >   return 0;<br>>> >> > > > > }<br>>> >> > > > ><br>
>> >> > > > > During dynamic initialization of i in function f() the value of<br>>> >> ar[0]<br>>> >> > > is 0<br>>> >> > > > > in case of clang were as in case of gcc it is 42.<br>
>> >> > > > ><br>>> >> > > > > As per standard(section 3.6.2) all global values should initially<br>>> >> be<br>>> >> > > zero<br>>> >> > > > > initialized followed by const initialized if possible before<br>
>> >> dynamic<br>>> >> > > > > initialization takes place.<br>>> >> > > > > Hence as per standard the const initialization of int ar[2] =<br>>> >> {42,i};<br>
>> >> > > > > should fail as i is not a const here( which seems to be happening<br>>> >> in<br>>> >> > > > > clang). Hence ar[0],ar[1] is still zero initialized because of<br>
>> >> which<br>>> >> > > during<br>>> >> > > > > dynamic initialization in f() ar[0]  is 0 which seems to be the<br>>> >> correct<br>>> >> > > > > behavior.<br>
>> >> > > > ><br>>> >> > > > > Can i conclude here that clang is behaving correctly and the tc is<br>>> >> > > wrong?<br>>> >> > > > > or am i missing something which this gcc tc wanted to capture?<br>
>> >> > > > ><br>>> >> > > ><br>>> >> > > > As far as I can tell, your analysis is correct.<br>>> >> > > ><br>>> >> > > > -Eli<br>
>> >> > ><br>>> >> > > Hi,<br>>> >> > > But isn't function f a constexpr? It doesn't modify anything and<br>>> >> always<br>>> >> > > returns 1.<br>
>> >> > ><br>>> >> > ><br>>> >> > It doesn't matter what the implementation of "f" is; "f()" is still not<br>>> >> a<br>>> >> > constant expression.  Please read [basic.start.init] and [expr.const] in<br>
>> >> > the C++ standard.<br>>> >> ><br>>> >> > -Eli<br>>> >><br>>> >> Hi Eli,<br>>> >> OK. I agree. f() is not a constexpr because the body of the function is<br>
>> >> not a<br>>> >> return statement. There are other prob