optimization bug? in initialization of class variable
Joe Buck
jbuck@synopsys.COM
Fri Dec 14 11:27:00 GMT 2001
> In the attached example, GCC (2.95, also 3.0) checks accessibility of
> the constructors (verify by uncommenting the "private:"), but avoids
> creating the temporary, even though its constructor has a side effect.
> The program outputs 0. I am surprised. Is the theory that
> accessibility is a "semantic restriction" but the side effect is merely
> "semantics"? Or is this a bug plain and simple?
The standard says that under certain circumstances copies can be optimized
away even if the copy constructor has or might have a side effect.
Roughly speaking, the compiler is allowed to assume that the only reason
for a copy constructor is to make a copy, so if the compiler can avoid
making a copy it is entitled to do so.
More information about the Gcc
mailing list