[PATCH] D146030: [clang][Interp] Handle LambdaExprs
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun May 7 01:03:09 PDT 2023
tbaeder added inline comments.
================
Comment at: clang/test/AST/Interp/lambda.cpp:92
+ static_assert(foo() == 1); // expected-error {{not an integral constant expression}}
+}
+
----------------
aaron.ballman wrote:
> How about some tests like:
> ```
> constexpr int call_thru_func_ptr(int i) {
> auto l = [](int i) { return i; };
> int (*fp)(int) = l;
> return fp(i);
> }
> static_assert(call_thru_func_ptr(12) == 12);
>
> constexpr int call_through_copied_lambda(auto lam, int i) {
> auto copy = lam;
> return copy(i);
> }
>
> constexpr int call_through_copied_lambda(auto lam) {
> auto copy = lam;
> return copy();
> }
>
> void func() {
> constexpr int i = 12;
> static_assert(call_through_copied_lambda([i]() { return i; }) == 12);
> }
> ```
Heh:
```
array.cpp:1245:15: error: static assertion expression is not an integral constant expression
1245 | static_assert(call_thru_func_ptr(12) == 12);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
array.cpp:1243:10: note: non-constexpr function '__invoke' cannot be used in a constant expression
1243 | return fp(i);
| ^
array.cpp:1245:15: note: in call to 'call_thru_func_ptr(12)'
1245 | static_assert(call_thru_func_ptr(12) == 12);
| ^
array.cpp:1239:12: note: declared here
1239 | auto l = [](int i) { return i; };
| ^
```
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D146030/new/
https://reviews.llvm.org/D146030
More information about the cfe-commits
mailing list