[cfe-commits] r91548 - in /cfe/trunk: include/clang/AST/ExprCXX.h lib/AST/ExprCXX.cpp lib/CodeGen/CGCXX.cpp lib/CodeGen/CGExprAgg.cpp lib/Frontend/PCHReaderStmt.cpp lib/Frontend/PCHWriterStmt.cpp lib/Sema/Sema.h lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaInit.cpp test/CodeGenCXX/value-init.cpp test/SemaCXX/dcl_init_aggr.cpp

Douglas Gregor dgregor at apple.com
Thu Dec 17 09:41:22 PST 2009


On Dec 17, 2009, at 1:37 AM, Sebastian Redl wrote:

>
> On Wed, 16 Dec 2009 16:21:19 -0800, Chris Lattner <clattner at apple.com>
> wrote:
>> On Dec 16, 2009, at 10:50 AM, Douglas Gregor wrote:
>>
>>> Author: dgregor
>>> Date: Wed Dec 16 12:50:27 2009
>>> New Revision: 91548
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=91548&view=rev
>>> Log:
>>> When value-initializing a class with no user-defined constructors  
>>> but
>>> with a non-trivial default constructor, zero-initialize the storage
>>> and then call the default constructor. Fixes PR5800.
>>
>> Is this really required?  My understanding was that the only case  
>> in C+
>> +'98 when an unconstructed object is guaranteed to zero filled is in
>> the global variable case.  Is this true in general, and if not, why
>> pay the performance cost to do the zero fill?
>
> Value-initialized != unconstructed. Value-initialized is the formal  
> name
> for what is done to objects without user-defined default constructor
> initialized with '()' in new-expressions and initializer lists, as  
> well as
> objects in an array with initializer of insufficient size. It's also  
> what
> will happen to objects initialized with the uniform initializer '{}'  
> in
> C++0x.

Right. You don't get value-initialization (with the zero-fill) for  
something like

   void f() {
     X x;
   }

but you would get it for something like:

   struct Y {
     X x;
     Y() : x() { }
   };

The motivation for the change to zero-initialize first then call the  
default constructor is that a value-initialized object should be  
identical to a global variable of the same type, as noted here:

	http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#302

	- Doug



More information about the cfe-commits mailing list