https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108893

--- Comment #11 from Jonny Grant <jg at jguk dot org> ---
As you say, in your quote from the manual, the access attribute read_only
doesn't mean there will be any access at all.
However, it doesn't seem to generate any warnings itself, maybe it is only for
the optimizer to utilize this knowledge.


Quoting the manual:
"The read_only access mode specifies that the pointer to which it applies is
used to read the referenced object but not write to it. Unless the argument
specifying the size of the access denoted by size-index is zero, the referenced
object must be initialized."


I tried size-index of 0, and 1, but it doesn't make any difference.

Updated example:
https://godbolt.org/z/Ms3zWThjT


So if I need such nullptr warnings where it is passed and the optimizer can see
it, I should use -Wnonnull and attribute nonnull on those functions. Perhaps
via a macro, so only in a special build run occasionally to check for such
issues.

Reply via email to