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] PR 7776: Warn about if ("abc" < "xyz") ...

> Roger Sayle wrote:
> The following patch is my proposed solution to PR middle-end/7776
> which is an enhancement request that gcc warn about comparisons to
> constant string literals. ...

By analogy, this should likely apply to all literal value addresses,
including arbitrary complex literals, i.e.:

- "abc"
- (char []){'a','b','c', 0} // which is equivelent to a string literal.
- &'a' or &(<sometype>)some_literal_value
- (some_struct_or_array){some_literal, ...}

As all are subject to the same root problem, being that the standard does
not define if lexically distinct instances of otherwise equivalently valued
literals are required to be logically identical or unique objects; therefore
not a unique issue relating to string-literals.

Unfortunately however as there is no present facility to qualify pointers to
literal values; there is no ability to differentiate between literal vs.
variable object references once a literal address is assigned to a variable,
or passed as an argument to, or a return from a function.

(Maybe it's worth while to add a 'literal' qualifier extension to GCC to
enable such indirect references to READONLY literal objects to be ideally
differentiated from variable objects; possibly setting a precedent for
future standard incorporation. As otherwise the proper handling of literal
references which can not be reliably presently satisfied.)

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