Skip to content

Commit 85e6e71

Browse files
committed
[clang][Interp] Handle discarded PointerToIntegral casts
Resolve an old TODO comment.
1 parent b56b3d7 commit 85e6e71

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
167167
return this->emitNull(classifyPrim(CE->getType()), CE);
168168

169169
case CK_PointerToIntegral: {
170-
// TODO: Discard handling.
170+
if (DiscardResult)
171+
return this->discard(SubExpr);
172+
171173
if (!this->visit(SubExpr))
172174
return false;
173175

clang/test/AST/Interp/c.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ _Static_assert(!!1, "");
2424
int a = (1 == 1 ? 5 : 3);
2525
_Static_assert(a == 5, ""); // all-error {{not an integral constant expression}}
2626

27+
const int DiscardedPtrToIntCast = ((intptr_t)((void*)0), 0); // all-warning {{left operand of comma operator has no effect}}
2728

2829
const int b = 3;
2930
_Static_assert(b == 3, ""); // pedantic-ref-warning {{not an integer constant expression}} \

0 commit comments

Comments
 (0)