This is the mail archive of the gcc@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]

Re: Semantics of MODIFY_EXPR with CONSTRUCTOR rhs


Richard Henderson <rth@redhat.com> writes:

| On Mon, Aug 02, 2004 at 10:15:02AM +0200, Gabriel Dos Reis wrote:
| > | >   r = {.x=5, .y=8};
| > | >   r = {.x=1, .y=r.x};
| ...
| > My understanding is that it is a behvaiour unspecified by the C99
| > standard, 6.7.8 Initialization:
| > 
| >        [#23] The order in which any side effects  occur  among  the
| >        initialization list expressions is unspecified.130)
| 
| Irrelevant.  In C99, constructors can happen in only two places:
| 
|   (1) The declaration.  In which case we *can't* have assigned
|       to the object before, so self-reference can only be erroneous.

I disagree, self-reference is not invalid.  Whether you have assigned
the object before is irrelevant.  Again consider

    void* p = &p;

and its variant

    struct S { void* data; };
    struct S s = { &s.data };

If we condider a declaration of the form

   struct point r = { .x = 1, .y = r.x };

r.x is reading an indeterminate value. 

|   (2) A compound literal.  In which case we explicitly are creating
|       a temporary object, which means that the entire rhs *must* be
|       constructed first.

And r.x in the second statement provided by Kenner does not
refer to the the temporary object, but to the variable r.  

-- Gaby


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