[PATCH] D36915: [Sema] Diagnose local variables and parameters captured by lambda and block expressions in a default argument

Akira Hatanaka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 28 11:14:09 PDT 2017

ahatanak added a comment.

In https://reviews.llvm.org/D36915#849622, @faisalv wrote:

> I don't think this approach is entirely correct for at least the following reasons:
> 1. in the lambda case the machinery that diagnoses capture failures should be the machinery erroring on the lambda (when the parameter is odr-used)

Does this mean that it is OK to have a parameter or local variable appear in a potentially-evaluated expression as long as it is not odr-used? I think this is slightly different from the standard, which says a parameter or local variable cannot appear as a potentially-evaluated expression in a default argument.

For example:

  void foo2(int);
  void func() {
    const int a = 1;
    void foo1(S s = [](){ foo2(a); }); // "a" is not in an unevaluated context and is not odr-used.

I think I need clarification as it will affect how or where we detect this error.


More information about the cfe-commits mailing list