This is the mail archive of the gcc-patches@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: Unreviewed patch for c-decl.c


On Wed, 8 Oct 2003 22:24:44 +0100 (BST), "Joseph S. Myers" <jsm@polyomino.org.uk> wrote:

> On Wed, 8 Oct 2003, Dhananjay R. Deshpande wrote:
>
>> Yes. Actually the patch sets the type_quals for the DECL and does not modify 
>> the type of DECL. The comment in the patch is wrong. Its not "apply type_quals 
>> of array elements to array_type", but to the current DECL.
>
> I guess that the code that ensures that when type qualifiers are applied
> to an array type they get passed down to the element type is coming into
> play.  But even with a comment explaining this, relying on such a subtle
> effect would be bad design.  It also isn't clear that it would get the
> desired effect of the patch - allocation in .rodata - in all cases of
> multidimensional arrays.  Adjust the code that determines DECL_READONLY
> instead to check down inside arrays (including multidimensional arrays)  
> for the type qualifiers.

That's exactly what his patch is doing.  "type_quals" in grokdeclarator is
the set of qualifiers that are passed to c_apply_type_quals_to_decl, which
must (and does) include TYPE_QUAL_CONST for "const int foo[42];"  The same
should apply if the const comes from a typedef.

type_quals is also used for building qualified types, but
c_build_qualified_type knows that quals pass through arrays, so they are
properly applied to the element type, not the array type.

I'd prefer a patch that moves all of the array type handling code from the
C++ front end into c-common, but this patch is an improvement over the
status quo.  It looks fine to me.

Jason


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