Skip to content

Commit 51b54ff

Browse files
authored
[clang][bytecode] Fix discarded dynamic casts (llvm#200723)
If they are checked.
1 parent 40b722d commit 51b54ff

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3570,6 +3570,8 @@ bool Compiler<Emitter>::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *E) {
35703570
if (!this->emitCheckDynamicCast(E))
35713571
return false;
35723572

3573+
if (DiscardResult)
3574+
return this->emitPopPtr(E);
35733575
return true;
35743576
}
35753577

clang/test/AST/ByteCode/cxx23.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,4 +641,8 @@ namespace DynamicCast {
641641
// all23-note {{dynamic_cast applied to object 'a' whose dynamic type is not constant}} \
642642
// all20-note {{function parameter 'a' with unknown value cannot be used in a constant expression}}
643643
}
644+
645+
struct S {};
646+
constexpr S s;
647+
constexpr int foo = (dynamic_cast<const S &>(s), 0);
644648
}

0 commit comments

Comments
 (0)