Created on 2012-02-08.00:00:00 last changed 36 months ago
Notes from the October, 2012 meeting:
The approach favored by CWG was to specify that the operand of typeid is considered to be odr-used for the purpose of determining capture.
[Resolved by the adoption of P0588R1 at the November, 2017 meeting.]
According to 7.5.6 [expr.prim.lambda] paragraph 11, a variable is implicitly captured if it is odr-used. In the following example,
struct P { virtual ~P(); }; P &f(int&); int f(const int&); void g(int x) { [=] { typeid(f(x)); }; }
x is only odr-used if the operand of typeid is a polymorphic lvalue; otherwise, the operand is unevaluated (7.6.1.8 [expr.typeid] paragraphs 2-3). Whether the operand is a polymorphic lvalue depends on overload resolution in this case, which depends on whether x is captured or not: if x is captured, since the lambda is not mutable, the type of x in the body of the lambda is const int, while if it is not captured, it is just int. However, the const int version of f returns int and the int version of f returns a polymorphic lvalue, leading to a conundrum: x is only captured if it is not captured, and vice versa.
History | |||
---|---|---|---|
Date | User | Action | Args |
2021-11-15 00:00:00 | admin | set | status: drafting -> cd5 |
2012-11-03 00:00:00 | admin | set | messages: + msg4090 |
2012-11-03 00:00:00 | admin | set | status: open -> drafting |
2012-02-08 00:00:00 | admin | create |