[PATCH] Fix PR19010

Richard Smith richard at metafoo.co.uk
Sat Mar 1 21:34:50 PST 2014


  LGTM, do you need someone to commit for you?


================
Comment at: lib/AST/ExprConstant.cpp:5120-5121
@@ -5119,11 +5119,4 @@
 
-    if (ZeroInit)
-      return ZeroInitialization(E);
-
-    const CXXRecordDecl *RD = FD->getParent();
-    if (RD->isUnion())
-      Result = APValue((FieldDecl*)0);
-    else
-      Result = APValue(APValue::UninitStruct(), RD->getNumBases(),
-                       std::distance(RD->field_begin(), RD->field_end()));
-    return true;
+    // We zero-initialize even if E does not require zero-initialization
+    // because this a simple way to ensure that empty bases are initialized.
+    return ZeroInitialization(E);
----------------
It would be better to point to language semantics here:

Either we're performing value-initialization, or we're default-initializing an object with a trivial constexpr default constructor. In the latter case, the lifetimes of base class subobjects start at this point per [basic.life]p1 and there are no non-static data members, so zero-initialization is appropriate either way.


http://llvm-reviews.chandlerc.com/D2909



More information about the cfe-commits mailing list