]> granicus.if.org Git - clang/commitdiff
[c++2a] Fix assertion failure if we would walk over more than one level
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 30 May 2019 20:45:12 +0000 (20:45 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 30 May 2019 20:45:12 +0000 (20:45 +0000)
of derived-to-base conversion path when implicitly starting union
subobject lifetimes in constant evaluation.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@362147 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprConstant.cpp
test/SemaCXX/constant-expression-cxx2a.cpp

index ac21b63cc79bbc246d2c7787a76311ea0921146f..df9b3067b8d43fad2e24035e113a03d647397d21 100644 (file)
@@ -5031,7 +5031,8 @@ static bool HandleUnionActiveMemberChange(EvalInfo &Info, const Expr *LHSExpr,
       if (ICE->getCastKind() != CK_DerivedToBase &&
           ICE->getCastKind() != CK_UncheckedDerivedToBase)
         break;
-      for (const CXXBaseSpecifier *Elt : ICE->path()) {
+      // Walk path backwards as we walk up from the base to the derived class.
+      for (const CXXBaseSpecifier *Elt : llvm::reverse(ICE->path())) {
         --PathLength;
         (void)Elt;
         assert(declaresSameEntity(Elt->getType()->getAsCXXRecordDecl(),
index aa534ce592e34841499f326708002db56a66399c..f29f4beb2908228db31ec8d6dea0e803667d7ef9 100644 (file)
@@ -521,4 +521,14 @@ namespace Union {
     u1 = u2;
     return true;
   }();
+
+  struct S1 {
+    int n;
+  };
+  struct S2 : S1 {};
+  struct S3 : S2 {};
+  void f() {
+    S3 s;
+    s.n = 0;
+  }
 }