[PATCH] D137232: [clang][Interp] Support inc/dec operators on pointers

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 9 11:07:37 PST 2022


aaron.ballman added inline comments.


================
Comment at: clang/test/AST/Interp/arrays.cpp:216
 
-  static_assert(getNextElem(E, 1) == 3);
-#endif
+  static_assert(getNextElem(E, 1) == 3, "");
+
----------------
aaron.ballman wrote:
> I'd like test cases where the pointer arithmetic has run off the beginning/end of the object (forming the invalid pointer is UB per http://eel.is/c++draft/expr.add#4.3 even if you never dereference the pointer).
```
constexpr int bad1() {
  const int *e =  E + 3;
  e++; // This is fine because it's a one-past-the-end pointer
  return *e; // This is UB
}

constexpr int bad2() {
  const int *e = E + 4;
  e++; // This is UB
  return *e; // This is UB as well
}

constexpr int bad3() {
  const int *e = E;
  --e; // This is UB
  return *e; // This is UB as well
}
```


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137232/new/

https://reviews.llvm.org/D137232



More information about the cfe-commits mailing list