Open
Description
Just realized the test below is part of https://bugs.eclipse.org/bugs/show_bug.cgi?id=561128 discussion.
The following code is at least c++17
because it evaluates constexpr lambda
in constexpr context.
Computed result
value is integer 2
.
Eclipse CDT supports constexpr lambda
and is able to perform evaluation thereof.
Unfortunately CDT evaluations of both local lambdas effectively capture acc
by value so calling any of them do not affect the acc
in enclosing function scope. This causes CDT to evaluate lambdainc()
as integer 0
which yields wrong non-type argument to Evaluate<>
.
template<int V> struct Evaluate {};
template<> struct Evaluate<2> { static constexpr int value = 2; };
constexpr auto lambdainc()
{
int acc = 0;
auto incDefaultCapture = [&]() constexpr { return ++acc; };
auto incCaptureByReference = [&acc]() constexpr { return ++acc; };
incDefaultCapture();
incCaptureByReference();
return acc;
}
// Error mark on 'result' initializer below says: Symbol 'value' could not be resolved
// this is because lamdainc() is currently evaluated to 0 and Evaluate<0> does not contain 'value'
static constexpr auto result = Evaluate<lambdainc()>::value;
Expected behavior
CDT evaluation of both lamdas should capture acc
from enclosing function scope by reference.
lambdainc()
should evaluate as integer 2