mirror of
https://forge.sourceware.org/marek/gcc.git
synced 2026-02-22 20:01:31 -05:00
When we refer to a captured variable from a constant-expression context inside a lambda, the closure (like any function parameter) is not constant because we aren't in a call, so we don't have an argument. So the capture is non-constant. But if the captured variable is constant, we might be able to use it directly in constexpr evaluation. PR c++/82643 PR c++/87327 * constexpr.c (cxx_eval_constant_expression): In a lambda function, try evaluating the captured variable directly. From-SVN: r269951
24 lines
317 B
C
24 lines
317 B
C
// PR c++/87327
|
|
// { dg-do compile { target c++17 } }
|
|
|
|
template <int N>
|
|
struct Foo {
|
|
constexpr auto size() const {
|
|
return N;
|
|
}
|
|
};
|
|
|
|
constexpr int foo() {
|
|
constexpr auto a = Foo<5>{};
|
|
|
|
[&] {
|
|
Foo<a.size()> it = {};
|
|
|
|
return it;
|
|
}();
|
|
|
|
return 42;
|
|
}
|
|
|
|
constexpr int i = foo();
|