[PATCH] D132111: [clang][Interp] Implement pointer (de)ref operations and DeclRefExprs

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 19 22:04:09 PDT 2022


tbaeder marked 5 inline comments as done.
tbaeder added inline comments.


================
Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:662
+      return this->emitGetPtrParam(It->second, E);
+  }
+
----------------
tahonermann wrote:
> Perhaps add:
>   else {
>     assert(0 && "Unhandled declaration kind");
>   }
We actually hit this path for non-constexpr-conforming functions, so asserting doesn't work:
```
constexpr void foo(int a) {
  constexpr int b = a;
}
```
The initializer for `b` goes through `evaluteAsInitializer()` before the function `foo` is ever registered, so the parameter is not known. This is diagnosed by the current interpreter as well:

```
array.cpp:13:17: error: constexpr variable 'b' must be initialized by a constant expression
  constexpr int b = a;
                ^   ~
array.cpp:13:21: note: function parameter 'a' with unknown value cannot be used in a constant expression
  constexpr int b = a;
                    ^
array.cpp:12:24: note: declared here
constexpr void foo(int a) {
                       ^
```

Would be a good future test case, but right now the error message for the new interpreter is just "constexpr variable 'b' must be initialized by a constant expression".


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

https://reviews.llvm.org/D132111



More information about the cfe-commits mailing list