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

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 11 04:22:06 PST 2022


tbaeder 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:
> 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
> }
> ```
Interesting side-effect of removing the `Run` call in `isPotentialConstantExpression()`: The new constant interpreter doesn't diagnose the "never produces a constant expression` case. The function must be called for any diagnostics to be printed.


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

https://reviews.llvm.org/D137232



More information about the cfe-commits mailing list