From: Paul Bibbings on
In [expr.prim.lambda], ��5.1.2/11 it says:

"If a lambda-expression has an associated capture-default and its
compound-statement uses (3.2) this or a variable with automatic
storage duration and the used entity is not explicitly captured, then
the used entity is said to be implicitly captured."

Later, in ��5.1.2/13:

"A lambda-expression appearing in a default argument shall not
implicitly or explicitly capture an entity."

and it gives the following Example (reduced for relevance to the current
post):

void f2() {
int i = 1;
// ...
void g5(int = ([]{ return sizeof i; })()); // OK
}

>From the above, my reading is that g5 is OK since the presence of i does
not, in this context, constitute a 'use'. Thus, from [basic.def.odr],
��3.2/2:

"An expression is potentially evaluated unless it is an unevaluated
operand (Clause 5) or a subexpression thereof. A variable or
non-overloaded function whose name appears as a potentially-evaluated
expression is used ..."

and, of course, this is the case for the operand to sizeof in the
example above:

[expr.sizeof] ��5.3.3/1:

"The sizeof operator yields the number of bytes in the object
representation of its operand. The operand is either an expression,
which is an unevaluated operand (Clause 5), or a parenthesized
type-id."

What appears to be missing in [expr.prim.lambda] (unless it is me that
is missing something) is some statement indicating how it happens - in
the absence of explicit or implicit capture - that i is nevertheless
`available' in the context of the compound-statement of the
lambda-expression in g5, above; in effect, by what mechanism it is
available outside of being captured.

I am wanting to get a better sense of this since gcc-4.5.0 does not
accept the above code, failing it with:

11:53:03 Paul Bibbings(a)JIJOU
/cygdrive/d/CPPProjects/nano/gcc_bugs $cat _5_1_2_13.cpp
// file: _5_1_2_13.cpp

void f2() {
int i = 1;
// ...
void g5(int = ([]{ return sizeof i; })());
}

11:53:06 Paul Bibbings(a)JIJOU
/cygdrive/d/CPPProjects/nano/gcc_bugs $i686-pc-cygwin-gcc-4.5.0 -Wall
-Wno-unused -std=c++0x -pedantic -c _5_1_2_13.cpp
_5_1_2_13.cpp: In lambda function:
_5_1_2_13.cpp:6:37: error: local variable ��i�� may not appear in this
context
_5_1_2_13.cpp:6:40: error: return-statement with a value, in function
returning 'void'
_5_1_2_13.cpp: In function ��void f2()��:
_5_1_2_13.cpp:6:44: error: default argument for ��int <anonymous>�� has
type ��void��

Regards

Paul Bibbings



--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]