Skip to content

Commit ecbd2d5

Browse files
authored
[clang][ExprConst] Diagnose ptr subs with non-zero offset (#135938)
The attached test case was missing the note.
1 parent 909a9fe commit ecbd2d5

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

clang/lib/AST/ExprConstant.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -14764,9 +14764,6 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
1476414764
// Reject differing bases from the normal codepath; we special-case
1476514765
// comparisons to null.
1476614766
if (!HasSameBase(LHSValue, RHSValue)) {
14767-
// Handle &&A - &&B.
14768-
if (!LHSValue.Offset.isZero() || !RHSValue.Offset.isZero())
14769-
return Error(E);
1477014767
const Expr *LHSExpr = LHSValue.Base.dyn_cast<const Expr *>();
1477114768
const Expr *RHSExpr = RHSValue.Base.dyn_cast<const Expr *>();
1477214769

clang/test/AST/ByteCode/arrays.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static_assert(k1 == 1, "");
107107
static_assert((&arr[0] - &arr[1]) == -1, "");
108108

109109
constexpr int k2 = &arr2[1] - &arr[0]; // both-error {{must be initialized by a constant expression}} \
110-
// expected-note {{arithmetic involving unrelated objects}}
110+
// both-note {{arithmetic involving unrelated objects}}
111111

112112
static_assert((arr + 0) == arr, "");
113113
static_assert(&arr[0] == arr, "");

clang/test/SemaCXX/constant-expression-cxx11.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,10 @@ constexpr int a = 0;
409409
constexpr int b = 1;
410410
constexpr int n = &b - &a; // expected-error {{must be initialized by a constant expression}} \
411411
// expected-note {{arithmetic involving unrelated objects '&b' and '&a' has unspecified value}}
412+
constexpr static int arrk[2] = {1,2};
413+
constexpr static int arrk2[2] = {3,4};
414+
constexpr int k2 = &arrk[1] - &arrk2[0]; // expected-error {{must be initialized by a constant expression}} \
415+
// expected-note {{arithmetic involving unrelated objects}}
412416

413417
namespace MaterializeTemporary {
414418

0 commit comments

Comments
 (0)