diff options
-rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 3 | ||||
-rw-r--r-- | clang/test/SemaCXX/constant-expression-cxx2a.cpp | 10 |
2 files changed, 12 insertions, 1 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index ac21b63cc79..df9b3067b8d 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -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(), diff --git a/clang/test/SemaCXX/constant-expression-cxx2a.cpp b/clang/test/SemaCXX/constant-expression-cxx2a.cpp index aa534ce592e..f29f4beb290 100644 --- a/clang/test/SemaCXX/constant-expression-cxx2a.cpp +++ b/clang/test/SemaCXX/constant-expression-cxx2a.cpp @@ -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; + } } |