This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 108i. See for the official list.


1612. Implicit lambda capture and anonymous unions

Section:  [expr.prim.lambda.capture]     Status: C++14     Submitter: Michael Wong     Date: 2013-01-31

N3690 comment CA 17

[Moved to DR at the February, 2014 meeting.]

It is not clear from the description of capturing in 7.5.5 [expr.prim.lambda] whether an implicit capture resulting from the odr-use of a member of an anonymous union captures that member or the anonymous union, and there is implementation divergence. For example,

  int main() {
    static int result;
    struct A { int x; };
    struct B { int y; };
    union {
      A a; B b;
    a.x = 1;
    [=]() mutable { a.x = 2; result = b.y; }();
    if (result == 1) return 0;
    throw 0;

Notes from the April, 2013 meeting:

CWG decided that an attempt to capture a member of an anonymous union should be ill-formed.

Proposed resolution (September, 2013):

  1. Change 7.5.5 [expr.prim.lambda] paragraph 15 as follows:

  2. ...An array of runtime bound ( [dcl.array]) or a member of an anonymous union shall not be captured by copy.
  3. Change 7.5.5 [expr.prim.lambda] paragraph 16 as follows:

  4. ...It is unspecified whether additional unnamed non-static data members are declared in the closure type for entities captured by reference. A member of an anonymous union shall not be captured by reference. [Note:...