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: Compiling GCC With a C++ Compiler (g++)


Andreas Schwab <schwab@suse.de> writes:

| Gabriel Dos Reis <gdr@cs.tamu.edu> writes:
| 
| > Andreas Schwab <schwab@suse.de> writes:
| >
| > | Gabriel Dos Reis <gdr@cs.tamu.edu> writes:
| > | 
| > | > Phil Edwards <phil@codesourcery.com> writes:
| > | >
| > | > [...]
| > | >
| > | > | particular place.  Since member init-lists aren't available for STRING_CST,
| > | > | we have to cast away the const in build_string
| > | >
| > | > which is undefined behaviour by C rules  (and C++ too).
| > | 
| > | Only if the underlying object is really read-only, which it isn't.
| >
| > I'm talking about the subobject for the string.
| 
| The subobject is still part of a wholly writable object (as returned by
| ggc_alloc_tree).

The fact that the subboject is part of a "whole writebale" object does
not make the subobject suddenly writable.
Looking more closely the language in 6.3.2.1.

       [#1]  An  lvalue  is an expression with an object type or an
       incomplete  type  other  than void;53) if an lvalue does not
       designate an object when it is evaluated,  the  behavior  is
       undefined.   When  an  object  is  said to have a particular
       type, the type is specified by the lvalue used to  designate
       the  object.  A modifiable lvalue is an lvalue that does not
       have array type, does not have an incomplete type, does  not
       have  a  const-qualified  type,  and if it is a structure or
       union, does not have any member (including, recursively, any
       member  or  element  of  all contained aggregates or unions)
       with a const-qualified type.


This language makes any lvalue whose type is whole tree_string
non-modifiable (this rule is very different from C++).  So Geoff's
change introduces undefined behaviour at many places, not just for the
string subobject part. 

-- Gaby

Interestingly, while this appear in the section on "restrict", it
gives you food for thought

       6.7.3.1  Formal definition of restrict

       [#1] Let D be a declaration of an ordinary  identifier  that
       provides  a  means of designating an object P as a restrict-
       qualified pointer to type T.

       [...]

       [#4] During each execution of B, let L be  any  lvalue  that
       has  &L based on P.  If L is used to access the value of the
       object X that it designates, and X is also modified (by  any
       means),  then  the following requirements apply: T shall not
       be const-qualified. [...]


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