This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-11-11


2086. Reference odr-use vs implicit capture

Section: 7.5.6.3  [expr.prim.lambda.capture]     Status: drafting     Submitter: Hubert Tong     Date: 2015-02-14

Whether a reference is odr-used or not has less to do with the context where it is named and more to do with its initializer. In particular, 7.5.6 [expr.prim.lambda] bullet 12.2 leads to cases where references that can never be odr-used are implicitly captured:

A lambda-expression with an associated capture-default that does not explicitly capture this or a variable with automatic storage duration (this excludes any id-expression that has been found to refer to an init-capture's associated non-static data member), is said to implicitly capture the entity (i.e., this or a variable) if the compound-statement:

For example, ref should not be captured in the following:

  struct A {
    A() = default;
    A(const A &) = delete;
  } globalA;

  constexpr bool bar(int &, const A &a) { return &a == &globalA; }

  int main() {
    A &ref = globalA;
    [=](auto q) { static_assert(bar(q, ref), ""); }(0);
  }