This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/18814] Incorrect reinitialization of compound literal


------- Additional Comments From joseph at codesourcery dot com  2004-12-03 19:28 -------
Subject: Re:  Incorrect reinitialization of compound literal

On Fri, 3 Dec 2004, austern at apple dot com wrote:

> Not exactly.  We still point to the same (one-element) array of ints we 
> did before.  The array is modifiable, and we're changing the value of 
> the first element in the array.  You might think that we should be 
> reinitializing the object, but that's wrong.  When we execute that 
> statement a second time all we're doing is setting p to the address of 
> the compound literal again, but we have change the value of that 
> compound literal.

It doesn't make any sense to do anything other than reinitialize the 
compound literal object.  The initializer values cannot meaningfully be 
evaluated until the compound literal is reached in execution, and once it 
is reached it would be bizarre for the initializers not to be evaluated - 
the only case where initializers may not be evaluated are where they are 
overridden - or for the initializers to be evaluated and discarded.

> The example in 6.5.2.5/16 is testing something completely different.  
> It checks to make sure that we're only creating the object once.  My 
> test case checks for that (yes, we get that right; we only create the 
> object once) and also checks to make sure that changes in the object 
> are reflected correctly.

It tests both that there's just one object and that the initializer is 
evaluated each time and used for initialization each time.  If it were 
evaluated only once, j would never reach 2; if the literal were 
initialized only once, q->i would stay at 0.

I consider the standard entirely clear here; although I'm aware that a 
proprietary testsuite differs on this matter, I think it is quite clearly 
their bug.



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18814


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]