This is the mail archive of the 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: [PATCH] Set TREE_READONLY const POD arrays with sizedetermined from initialize (PR c++/21454) â

> From: Mark Mitchell <>
>> Paul Schlie wrote:
>>> Jakub Jelinek <> writes:
>>> This is a fallout of the PR c++/20073 fix.
>>> For arrays like:
>>> const int a[] = { 0, 1, 2, 3 };
>>> when cp_apply_type_quals_to_decl is called, its type is not complete yet,
>>> so C++ frontend does not set TREE_READONLY flag.  But such variables
>>> aren't put into incomplete_vars chain either, so nothing sets the flag
>>> afterwards.
>>> Ok for 4.0/HEAD if it passes regtesting?
>> What's the difference between TREE_READONLY and MEM_READONLY_P ?
>> (To the best of my knowledge "const int a[]" is allocated and initialized
>>  at run-time in RAM with the READONLY ROM literal value "{1,2,3,4}"; so a[]
>>  is not READONLY, although it's literal initializer is; as opposed to
>>  "static const a[] = {0,1,2,3}" where they are considered equivalent.)
> I'm not sure exactly what you're asking.  But, "a" should be
> TREE_READONLY in that case, as there should be no dynamic
> initialization, and nothing may ever change the value.
> It's associated MEM should also be MEM_READONLY_P.

Sorry, I'll try to be more clear. My fundamental confusion is about what the
criteria for designating a variable/literal value READONLY is?

As I thought it was exclusively only "static const" variables initialized
with a literal value, or an anonymous literal values themselves which were
"READ-ONLY/ROM-able".  Where "const" variables, although semantically
restricted, are presumed to be dynamically allocated, and initialized in
"RAM", and may in fact be modifiable through pointer casts etc., therefore
can't be READONLY, but just "const".

(So I'm confused, as I don't believe "const int a[]" declares a READONLY

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