[llvm-branch-commits] [cfe-branch] r204263 - Merging r203025:

Tom Stellard thomas.stellard at amd.com
Wed Mar 19 13:38:17 PDT 2014


Author: tstellar
Date: Wed Mar 19 15:38:17 2014
New Revision: 204263

URL: http://llvm.org/viewvc/llvm-project?rev=204263&view=rev
Log:
Merging r203025:

------------------------------------------------------------------------
r203025 | richard-llvm | 2014-03-05 15:32:50 -0800 (Wed, 05 Mar 2014) |
3 lines

PR19010: Make sure we initialize (empty) indirect base class subobjects
when
evaluating trivial default initialization of a literal class type.

Modified:
    cfe/branches/release_34/lib/AST/ExprConstant.cpp
    cfe/branches/release_34/test/SemaCXX/constant-expression-cxx11.cpp

Modified: cfe/branches/release_34/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_34/lib/AST/ExprConstant.cpp?rev=204263&r1=204262&r2=204263&view=diff
==============================================================================
--- cfe/branches/release_34/lib/AST/ExprConstant.cpp (original)
+++ cfe/branches/release_34/lib/AST/ExprConstant.cpp Wed Mar 19 15:38:17 2014
@@ -5089,16 +5089,15 @@ bool RecordExprEvaluator::VisitCXXConstr
     if (!Result.isUninit())
       return true;
 
-    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 can get here in two different ways:
+    //  1) We're performing value-initialization, and should zero-initialize
+    //     the object, or
+    //  2) We're performing default-initialization of an object with a trivial
+    //     constexpr default constructor, in which case we should start the
+    //     lifetimes of all the base subobjects (there can be no data member
+    //     subobjects in this case) per [basic.life]p1.
+    // Either way, ZeroInitialization is appropriate.
+    return ZeroInitialization(E);
   }
 
   const FunctionDecl *Definition = 0;
@@ -5578,19 +5577,9 @@ bool ArrayExprEvaluator::VisitCXXConstru
     if (HadZeroInit)
       return true;
 
-    if (ZeroInit) {
-      ImplicitValueInitExpr VIE(Type);
-      return EvaluateInPlace(*Value, Info, Subobject, &VIE);
-    }
-
-    const CXXRecordDecl *RD = FD->getParent();
-    if (RD->isUnion())
-      *Value = APValue((FieldDecl*)0);
-    else
-      *Value =
-          APValue(APValue::UninitStruct(), RD->getNumBases(),
-                  std::distance(RD->field_begin(), RD->field_end()));
-    return true;
+    // See RecordExprEvaluator::VisitCXXConstructExpr for explanation.
+    ImplicitValueInitExpr VIE(Type);
+    return EvaluateInPlace(*Value, Info, Subobject, &VIE);
   }
 
   const FunctionDecl *Definition = 0;

Modified: cfe/branches/release_34/test/SemaCXX/constant-expression-cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_34/test/SemaCXX/constant-expression-cxx11.cpp?rev=204263&r1=204262&r2=204263&view=diff
==============================================================================
--- cfe/branches/release_34/test/SemaCXX/constant-expression-cxx11.cpp (original)
+++ cfe/branches/release_34/test/SemaCXX/constant-expression-cxx11.cpp Wed Mar 19 15:38:17 2014
@@ -1863,3 +1863,13 @@ namespace BuiltinStrlen {
   constexpr char d[] = { 'f', 'o', 'o' }; // no nul terminator.
   constexpr int bad = __builtin_strlen(d); // expected-error {{constant expression}} expected-note {{one-past-the-end}}
 }
+
+namespace PR19010 {
+  struct Empty {};
+  struct Empty2 : Empty {};
+  struct Test : Empty2 {
+    constexpr Test() {}
+    Empty2 array[2];
+  };
+  void test() { constexpr Test t; }
+}





More information about the llvm-branch-commits mailing list