Skip to content

Commit f5544cf

Browse files
committed
[clang][bytecode] Fix discarding DerivedToBase casts
1 parent 0d39fe6 commit f5544cf

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
253253

254254
case CK_UncheckedDerivedToBase:
255255
case CK_DerivedToBase: {
256+
if (DiscardResult)
257+
return this->discard(SubExpr);
258+
256259
if (!this->delegate(SubExpr))
257260
return false;
258261

@@ -282,6 +285,9 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
282285
}
283286

284287
case CK_BaseToDerived: {
288+
if (DiscardResult)
289+
return this->discard(SubExpr);
290+
285291
if (!this->delegate(SubExpr))
286292
return false;
287293

clang/test/AST/ByteCode/records.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,3 +1684,18 @@ namespace ExplicitThisInTemporary {
16841684
constexpr bool g(B b) { return &b == b.p; }
16851685
static_assert(g({}), "");
16861686
}
1687+
1688+
namespace IgnoredMemberExpr {
1689+
class A {
1690+
public:
1691+
int a;
1692+
};
1693+
class B : public A {
1694+
public:
1695+
constexpr int foo() {
1696+
a;
1697+
return 0;
1698+
}
1699+
};
1700+
static_assert(B{}.foo() == 0, "");
1701+
}

0 commit comments

Comments
 (0)