[PATCH] D28467: [Sema] Add warning for unused lambda captures

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 19 05:16:33 PST 2017


On Thu, Jan 19, 2017 at 7:49 AM, Aaron Ballman <aaron.ballman at gmail.com> wrote:
> On Thu, Jan 19, 2017 at 4:37 AM, Malcolm Parsons
> <malcolm.parsons at gmail.com> wrote:
>> On 19 January 2017 at 03:47, Aaron Ballman <aaron.ballman at gmail.com> wrote:
>>> It is not used in an unevaluated context -- that is a bug.
>>
>> It is an evaluated expression, but is it odr-used?
>>
>> C++14 [basic.def.odr] p3:
>>
>> A variable x whose name appears as a potentially-evaluated expression
>> ex is odr-used by ex unless applying the lvalue-to-rvalue conversion
>> (4.1) to x yields a constant expression (5.20) that does not invoke
>> any nontrivial 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 (4.1) is applied to e, or e is a
>> discarded-value expression (Clause 5). ...
>>
>> 5.20 [expr.const] p3:
>>
>> An integral constant expression is an expression of integral or
>> unscoped enumeration type, implicitly converted to a prvalue, where
>> the converted expression is a core constant expression. [ Note: Such
>> expressions may be used as array bounds (8.3.4, 5.3.4), as bit-field
>> lengths (9.6), as enumerator initializers if the underlying type is
>> not fixed (7.2), and as alignments (7.6.2). — end note ]
>>
>> I read that as kDelta is not odr-used.
>>
>> GCC and ICC don't require kDelta to be captured either.
>
> You are correct, it is not an odr use. MSVC is wrong to require the capture.

I wasn't thinking about that kind of odr-unuse when reviewing your
patch, so I am starting to think that perhaps it's not worth
distinguishing unevaluated contexts or not in the diagnostic. :-( If
we could do it, then great (we seem to be able to do it for regular
variable use: http://coliru.stacked-crooked.com/a/4bde9b5daf48956a),
but if not, then I think we should just go back to the original
wording that says it's not required to be captured (in all cases, not
distinguishing odr-use) and put in a FIXME with the test cases that
could have an improved diagnostic (including the test case talked
about here, which we should add). What do you think?

~Aaron

>
> ~Aaron
>
>>
>> --
>> Malcolm Parsons


More information about the cfe-commits mailing list