[PATCH] D136528: [clang][Interp] Implement add and sub compound assign operators

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 24 06:55:38 PDT 2022


aaron.ballman added inline comments.


================
Comment at: clang/test/AST/Interp/literals.cpp:412
+
+  constexpr int getTwo() {
+    int i = 1;
----------------
I'd also like some test cases where the result of the operation is discarded. e.g.,
```
constexpr int func() {
  int i = 12;
  i += 10;
  return i;
}
static_assert(func() == 22);
```
and a test with a float-point type (okay for it to fail for the moment):
```
constexpr float func() {
  float f = 1.0f;
  f += 10.0f;
  return f;
}
static_assert(func() == 11.0f);
```


================
Comment at: clang/test/AST/Interp/literals.cpp:426
+  }
+  static_assert(subAll(213) == 0);
+
----------------
We also need tests for failure situations:
```
constexpr int func() {
  int i = __INT_MAX__;
  i += 1; // oops
  return i;
}

constexpr int another() {
  int i = __INT_MIN__;
  i -= 1; // oops
  return i;
}
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136528



More information about the cfe-commits mailing list