hankdane: yes, but is that ctor anything more than a potentially time-consuming no-op?
filthy_mcnasty: I disagree - I'm struggling to come up with any sensible reason for doing that - even if you do fix the leak:
Code:
int main(void)
{
int * p1 = new int(3);
// this seems really perverse..
int* p2 = p1;
p1 = new int(*p1); // clone
delete p2;
return 0;
}
or, if a copy was really wanted, why not "int* p2 = new int(*p1)". It's just that every time I try to think of some reason for doing that, there's a less awkard way to do the same thing.
So I maintain that you can't ignore the leak, because I can't see any purpose to the statement other than to leak memory. If anyone can think of a valid purpose for that statement, please post it here.
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
-- Sutter and Alexandrescu, C++ Coding Standards
Programs must be written for people to read, and only incidentally for machines to execute.
-- Harold Abelson and Gerald Jay Sussman
The cheapest, fastest and most reliable components of a computer system are those that aren't there.
-- Gordon Bell