it. And while I think the compiler should be allowed to generate the optimised code of 4.6 (i.e., the change is not a bug IMHO), I fully understand the idea of generating the older, slower, but definitely correct code of 4.5.
My understanding is that the standard mandates the old behavior, so 4.6 is in error.
I am still trying to imagine a real-world use-case for declaring an object "static const" and later accessing it as "volatile".
Yeah, it would seem far clearer to declare it as static const volatile in the first place.
I've done a bunch of automated testing of GCC's implementation of volatile. None of that testing would have exposed this bug because we only count acceses to objects declared as volatile.
I've come to the conclusion that "volatile" is a language design error. It complicates the compiler implementation and has confusing, underspecified semantics. If you want to force a load or store, an explicit function call is a clearer way to do it.
John