This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: optimization bug? in initialization of class variable



> 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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]