--- Comment #1 from crowl at google dot com 2007-10-31 20:08 ---
The wording in the C++ standard working paper is as follows:
8.5 Initializers [dcl.init]
-8- An object whose initializer is an empty set of parentheses, i.e.,
(), shall be value-initialized.
Therefore, in <<< Stats my_stats = Stats(); >>>, the temporary object
is value-initialized and then my_stats is copy-constructed.
-5- To value-initialize an object of type T means:
-- if T is a non-union class type without a user-provided
constructor, then every non-static data member and base-class
component of T is value-initialized;93)
93) Value-initialization for such a class object may be
implemented by zero-initializing the object and then calling
the default constructor.
-- if T is an array type, then each element is value-initialized;
-- otherwise, the object is zero-initialized
Therefore, the temporary should be zero-initialized and the resulting
copy should copy zeros. So, I conclude that gcc 4.2.1 is in error.
(I suspect the compiler already eliminates the copy.)
I suspect the problem arose in someone thinking that the zero
initialization in front of a call to a default constructor was
redundant. Alas, it is not. It is redundant only if the constructor
initializes all fields, which is generally unknowable, though the
compiler could determine so for many types and constructors.
--
crowl at google dot com changed:
What|Removed |Added
CC||crowl at google dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33916