tahonermann added inline comments.

================
Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:662
+      return this->emitGetPtrParam(It->second, E);
+  }
+
----------------
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?


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

https://reviews.llvm.org/D132111

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to