Unverified Commit 5e767bd7 authored by Daniel M. Katz's avatar Daniel M. Katz Committed by GitHub
Browse files

Push immediate function context while transforming lambdas in templates. (#89702)

The following program is [accepted](https://godbolt.org/z/oEc34Trh4

) by
Clang, EDG, and MSVC, but rejected by Clang:
```cpp
#include <vector>

consteval auto fn() { return std::vector {1,2,3}; }

template <typename T = int>
void fn2() {
    (void)[]() consteval {
      for (auto e : fn()) {}
    };
}

void caller() {
    fn2();
}
```

The stated diagnostic is:
```cpp
<source>:8:21: error: call to consteval function 'fn' is not a constant expression
    8 |       for (auto e : fn()) {}
```

The body of the lambda should be evaluated as within an immediate
function context when the lambda is marked as `consteval`.

Co-authored-by: default avatarcor3ntin <corentinjabot@gmail.com>
parent 08949464
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment