Skip to content

Commit 847d046

Browse files
committed
[clang][Interp] Fix comparing one-past-the-end pointers
1 parent c9fc960 commit 847d046

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

clang/lib/AST/Interp/Pointer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,8 @@ class Pointer {
513513
unsigned getByteOffset() const {
514514
if (isIntegralPointer())
515515
return asIntPointer().Value + Offset;
516+
if (isOnePastEnd())
517+
return PastEndMark;
516518
return Offset;
517519
}
518520

clang/test/AST/Interp/arrays.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ static_assert(foo[2][2] == nullptr, "");
2626
static_assert(foo[2][3] == &m, "");
2727
static_assert(foo[2][4] == nullptr, "");
2828

29+
constexpr int afterEnd[] = {1,2,3};
30+
static_assert(&afterEnd[3] == afterEnd + 3, "");
31+
2932
constexpr int ZeroSizeArray[] = {};
3033

3134
constexpr int SomeInt[] = {1};

0 commit comments

Comments
 (0)