llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) <details> <summary>Changes</summary> We can't call getBase(), so move the isRoot() check before. --- Full diff: https://github.com/llvm/llvm-project/pull/217540.diff 2 Files Affected: - (modified) clang/lib/AST/ByteCode/Interp.cpp (+4-3) - (modified) clang/test/AST/ByteCode/dynamic-cast.cpp (+15) ``````````diff diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index 7704550a12d82..8f0a36877aa2b 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -2246,15 +2246,16 @@ bool DynamicCast(InterpState &S, CodePtr OpPC, const Type *DestTypePtr, if (R.valid()) { Result = Iter.atField(*R.Offset); break; - } else if (R.Ambiguous) { + } + if (R.Ambiguous) { Ambiguous = true; break; } - // This moves us DOWN the type hierarchy. - Iter = Iter.getBase(); if (Iter.isRoot() || !Iter.isBaseClass()) break; + // This moves us DOWN the type hierarchy. + Iter = Iter.getBase(); } if (Ambiguous) diff --git a/clang/test/AST/ByteCode/dynamic-cast.cpp b/clang/test/AST/ByteCode/dynamic-cast.cpp index 83a745e271a28..8a4678b092c2e 100644 --- a/clang/test/AST/ByteCode/dynamic-cast.cpp +++ b/clang/test/AST/ByteCode/dynamic-cast.cpp @@ -352,3 +352,18 @@ namespace VirtualBase { } static_assert(test()); } + +namespace RootPtr { + struct S { + constexpr virtual int foo() { return 0; } + }; + + struct T {}; + + struct U : virtual T { + constexpr S *bar() const { return (S *)this; } // both-note {{cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression}} + }; + constexpr U u; + static_assert(dynamic_cast<T *>(u.bar())); // both-error {{not an integral constant expression}} \ + // both-note {{in call to}} +} `````````` </details> https://github.com/llvm/llvm-project/pull/217540 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
