
Originally Posted by
Andrew S
And, on other side (in opposing), there is a number of C++ compiler makers, that should think not about developers, but about quality and size of resulting code

The question really is whether the optimization is significant enough to make it worth adding the increased bug risk for developers. In this particular case, I would argue no, because the potential for damage is far greater than the doubtful benefits of optimization, in particular when I consider that this particular problem routinely has bitten the unwary for the past three decades.
Consider the following:
Code:
void foo(const TPtr&);
I can call this like so:
and everything will be well.
Now consider:
Code:
void foo(const TPtr&, int);
I can call this like so:
Code:
foo(new T, 99); // No problem
But, if I call it almost the same way, I have a potential problem:
Code:
foo(new T, bar()); // Might leak memory
This is truly hideous for a number of reasons.
For one, it is completely counter-intuitive that the following two code fragments do not do the same thing:
Code:
TPtr t = new T;
foo(t, bar());
This is not the same as:
That in itself is extremely ugly because most programmers looking at the two code fragments will conclude "They do the same thing."
But the real issue is the hidden maintenance problems. Consider the following code, which may have been working flawlessly for many years:
Now someone changes the implementation of bar such that it can throw an exception. All of a sudden, I have a potential memory leak. Worse, that leak will show up only if I happen to use a compiler that reorders the code in just the right way. And, because such code reordering typically only happens when optimization is enabled, but not for debug builds, even tools such as Purify are of limited help in tracking down the bug.
And we haven't even considered the difficulty of making bar throw during testing yet (which can be very difficult for some functions).
But, it's not just the implementation of bar that can cause this problem. Instead, it can be caused by any function that bar calls recursively. In other words, if I add a throw statement to the implementation of bar or any of the functions called by bar, I have to examine the entire call graph to see whether there might be a memory allocation and a call to bar (or any of the functions called by bar that now can throw an exception) without an intervening sequence point.
Doing this is next to impossible for large projects. And we haven't even considered yet that bar, or one of the functions called by bar, might be implemented in a third-party library that can change in arbitrary ways.
Even a statement such as the following is not entirely safe:
That's because, in the header file, I might have:
Code:
void foo(auto_ptr<T>, int = bar());
The undefined evaluation order of function arguments is also in conflict with exception safety. The whole point of exceptions is that I can throw them without having to worry about memory leaks, but the undefined evaluation order subverts that, even though I'm carefully using smart pointers.
Searching the web for relevant articles reveals that this issue (and the related issue of undefined evaluation of expressions that do not contain a sequence point) has bitten countless thousands of programmers time and time again. I wrote the broken code you pointed out myself, and I have been programming in C++ for twenty years now. I'm not a guru, but I consider myself quite experienced. Yet, I still wrote the bug (despite having known about the undefined evaluation order for more than two decades).
If it is that easy to write broken code, the problem is with the language, in my opinion. (In particular because the actual bug is highly unlikely to show up, except in rare and exotic circumstances.) The evaluation order is a carefully hidden trap that the language puts in the programmer's path so he can impale himself on the poisened spikes at the bottom...
More over, it is main paradigm of C++ - 'do not pay for what you do not use'.
The question is whether I really would pay in that case. As Bjarne says, he remains unconvinced, and so remain a lot of other people.
Thats my opinion, but it does not apply to my initial message - bugs, surely, are independed from our opinion
Absolutely! That's why it'll be fixed in Ice 3.3
And thanks again for reporting the bug!
Cheers,
Michi.