https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56973

--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> ---
Nathan mentioned today that we have the inverse problem as well: after we've
captured i, we should still be able to use its constant value.  Here's an
example of things that ought to work and mostly don't:

int main()
{ 
  const int i = 4;
  [] { constexpr int x = i; };
  [=] { &i; constexpr int x = i; };
  [&] { &i; constexpr int x = i; };
  [i] { &i; constexpr int x = i; };
  [&i] { &i; constexpr int x = i; };
}

"Every id-expression within the compound-statement of a lambda-expression that
is an odr-use (6.2) of an entity captured by copy is transformed into an access
to the corresponding unnamed data member of the closure type. [ Note: An
id-expression that is not an odr-use refers to the original entity, never to a
member of the closure type. Furthermore, such an id-expression does not cause
the implicit capture of the entity. — end note ]"

"A variable x whose name appears as a potentially-evaluated expression ex is
odr-used by ex unless applying the lvalue-to-rvalue conversion (7.1) to x
yields a constant expression (8.20) that does not invoke any non-trivial
functions and, if x is an object, ex is an element of the set of potential
results of an expression e, where either the lvalue-to-rvalue conversion (7.1)
is applied to e, or e is a discarded-value expression (Clause 8)."

Reply via email to