[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
Tue Aug 23 09:07:07 PDT 2022
tbaeder added inline comments.
================
Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:662
+ return this->emitGetPtrParam(It->second, E);
+ }
+
----------------
tahonermann wrote:
> tbaeder wrote:
> > 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".
> I see, interesting.
>
> I imagine future work will be needed to support references to lambda/block captures, data members, and such? And the answer to those right now is, we're not there yet?
Yes, almost nothing works right now. :)
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D132111/new/
https://reviews.llvm.org/D132111
More information about the cfe-commits
mailing list