Re: OON: Re: Aliasing and const

From: Arch Robison (robison@kai.com)
Date: Mon Mar 27 2000 - 09:59:25 EST


> > Const is almost useless for optimization. Consider a global declaration:
> >
> > const Foo x(2)
> >
> > Do I know that x never changes after initialization? I don't, because
> > I could have:
> >
> > Foo * Munger;
> >
> > struct Foo {
> > Foo( int j ) {...; Munger = this;}
> > };
> >
> > That is, the constructor might "capture" the pointer to x for use later.
>
> AFAIU, the above is not correct. Once the constructor for x has
> returned (and until the destructor begins running), x is "really const",
> and any modification via *Munger is undefined behavior. In other words,
> the optimizer can assume it is really-const.

You're right. I found the supporting text in 7.1.5.1p4 of the standard.
It says that attempts to modify non-mutable members of x during x's lifetime
results in undefined behavior.

- Arch

--------------------- Object Oriented Numerics List --------------------------
* To subscribe/unsubscribe: use the handy web form at
http://oonumerics.org/oon/
* If this doesn't work, please send a note to owner-oon-list@oonumerics.org



This archive was generated by hypermail 2b29 : Wed Feb 20 2002 - 03:20:11 EST