Dale Johannesen wrote:However, as a QOI issue, I believe the compiler should treat the reference as
volatile if either the object or the lvalue is volatile. That is obviously the
user's intent.
I'm not disagreeing with you, but I wonder at gcc's ability to make good on such a promise. A cast introducing a volatile qualifier will be a NOP_EXPR, and gcc tends to strip those at every opportunity.
You may well be right, I haven't tried to implement it (and am not planning to).
Also, I wonder about the following example
int const avail = <something>
int main() { while (*(int *)&avail == Foo ()) do_something(); return 0; }
Seeing through the const-stripping cast is a useful optimization.
It is? Why would somebody write that?
A further pathelogical case would be,
int main() { while (*(int *)(volatile int *)&avail) do_something (); return 0; }
What should this do, treat the volatile qualifier as sticky?
IMO, no, but surely we don't have to worry about this one. Either way
is standard conformant and the user's intent is far from clear, so whatever
we do should be OK.