[Bug c++/33916] Default constructor fails to initialize array members

2007-10-31 Thread gdr at gcc dot gnu dot org


--- Comment #2 from gdr at gcc dot gnu dot org  2007-11-01 02:16 ---
I concur with Lawrence' analysis.
I was bitten by this bug myself in my own code.


-- 

gdr at gcc dot gnu dot org changed:

   What|Removed |Added

 CC||gdr at gcc dot gnu dot org
 Status|UNCONFIRMED |NEW
 Ever Confirmed|0   |1
   Last reconfirmed|-00-00 00:00:00 |2007-11-01 02:16:55
   date||


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33916



[Bug c++/33916] Default constructor fails to initialize array members

2007-10-31 Thread crowl at google dot com


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