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]

Re: confused by code in C++ parser


Zack Weinberg wrote:
> 
> This is (a slightly edited form of) the primary: string-constant rule
> in the C++ parser.
> 
>         | STRING
>                 {
>                   /* c_build_string doesn't set up TYPE_MAIN_VARIANT of
>                      a const array the way we want, so fix it.  */
>                   if (flag_const_strings)
>                     TREE_TYPE ($$) = build_cplus_array_type
>                       (TREE_TYPE (TREE_TYPE ($$)),
>                        TYPE_DOMAIN (TREE_TYPE ($$)));
>                 }
> 
> Can someone please explain to me what c_build_string (formerly
> combine_strings) gets wrong about the type of a string constant for
> C++, and what the correct type is?  Thanks.
It's to do with array types. And yes, I think it could be done better.
There is a difference between C & C++ as to how const qualified
array types are represented. In the c front end, they ARRAY_TYPE is
qualified, in the c++ front end the outermost non-ARRAY_TYPE is qualified.
That's why build_cplus_array_type is there. Why the flag_const_string
is there, I don't know -- I think it's always 1.

We really should have some language dependant callback to do this right
in the first place -- as Mark found out when fixing some dwarf debug
output problem which had the same cause.

nathan

-- 
Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
         'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org


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