Patch for Bug No-8081

Gabriel Dos Reis gdr@integrable-solutions.net
Tue Sep 9 01:20:00 GMT 2003


"Zack Weinberg" <zack@codesourcery.com> writes:

|  /* If the return type is variably modified and we have no target to
|     initialize, we must use allocate_dynamic_stack_space to allocate a
|     temporary.  It becomes inaccessible at the end of the surrounding
|     expression, so its lifetime does not matter (it will be at least
|     that long).  */
| 
| Except, is that statement about its lifetime true?  There are a number
| of constructs that could be used to extend the life of the object,
| such as 
| 
|   int *p = &func().val[i];

there are many interesting issues here

  1) func().val is a non-lvalue array but I believe func().val[i] is
     an lvalue (because of array-to-pointer conversion and equivalent
     with *(func().val + i)

  2) I don't know how to interpret 6.5.2.2/5

                                                    If  an  attempt
       is made to modify the result of a function call or to access
       it after the next sequence point, the behavior is undefined.

     in this circumtance.

  3) C99 tried hard to make the result of function call a non-lvalue
     so as to avoid the issue of its lifetime.  But it could not avoid
     the above.  I would suggest the C++ rule here:  the lifetime of
     the function call lasts until the end of the full expression.
     That means that you cannot do anything meaningful with p.  Which I
     believe is a sensible semantic.


-- Gaby



More information about the Gcc mailing list