Skip to content

Commit 9b2285b

Browse files
committed
[clang][ExprConst] Diagnose ptr subs with non-zero offset
1 parent 11857be commit 9b2285b

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

clang/lib/AST/ExprConstant.cpp

Lines changed: 0 additions & 3 deletions
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/SemaCXX/constant-expression-cxx11.cpp

Lines changed: 4 additions & 0 deletions
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)