[Bug tree-optimization/80794] constant objects can be assumed to be immutable
pinskia at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed May 17 17:18:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80794
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Martin Sebor from comment #6)
> (In reply to Martin Sebor from comment #5)
> > S::i cannot change during the lifetime of an S object because S::i is
> > declared const. This holds regardless of whether the S object itself is
> > const.
>
> To be clear, the only way to change S::i is to destroy S or S::i and create
> a new object in its storage. That can be relied on not to happen in s.foo()
> because the reference s is seen used after the function returns.
I agree about foo but not about the call in bar.
Also you cannot use the undefinedness found in foo (that is the call to f in
foo cannot change the object) with the bar [if they are in the same translation
unit] as foo might not be called at runtime (and it is only runtime
undefinedness).
More information about the Gcc-bugs
mailing list