Re: missing optimization - don't compute return value not used?

2007-09-27 Thread Aaron W. LaFramboise
Richard Li wrote: Right, page 211 of the C++ standard (2003) explains when copy-ctor and dtor are allowed to be optimized away. But the two circumstances are both like this: A is constructed; A is copy-constructed to B; A is destructed Here A is a temporary object in some sense, and the

Re: missing optimization - don't compute return value not used?

2007-09-27 Thread Joe Buck
On Thu, Sep 27, 2007 at 01:17:58PM -0500, Aaron W. LaFramboise wrote: I think the biggest problem here is that GCC will not elide calls to the allocator. This is a subject of some controversy--even though its probably difficult to do such optimization anyway. It's not quite clear that

missing optimization - don't compute return value not used?

2007-09-26 Thread Neal Becker
gcc version 4.1.2 20070502 (Red Hat 4.1.2-12) I noticed the following code === version 1: templatetypename a_t, typename b_t inline a_t append (a_t a, b_t const b) { a.insert (a.end(), b.begin(), b.end()); return a; } === version 2: templatetypename a_t, typename b_t inline void append (a_t

Re: missing optimization - don't compute return value not used?

2007-09-26 Thread Richard Li
In version 1, the return type is a_t, so a class construction is required there (the caller will then destruct the returned object). Construction and destruction can have side effects, so the compiler would not drop them. For the following code, templatetypename a_t, typename b_t inline a_t

Re: missing optimization - don't compute return value not used?

2007-09-26 Thread Richard Li
Right, page 211 of the C++ standard (2003) explains when copy-ctor and dtor are allowed to be optimized away. But the two circumstances are both like this: A is constructed; A is copy-constructed to B; A is destructed Here A is a temporary object in some sense, and the standard allows for directly