[PATCH] D33526: Fix spurious Wunused-lambda-capture warning

Akira Hatanaka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 29 15:35:09 PDT 2017


ahatanak added inline comments.


================
Comment at: lib/Sema/SemaLambda.cpp:1524-1526
+      if (!CurContext->isDependentContext() && !IsImplicit)
+        if ((IsGenericLambda && !From.isNonODRUsed()) ||
+            (!IsGenericLambda && !From.isODRUsed()))
----------------
kongyi wrote:
> malcolm.parsons wrote:
> > Should generic lambdas and lambdas in a dependent context be treated the same?
> > 
> > Is a lambda inside a generic lambda in a dependent context?
> Generic lambdas are essentially templated lambdas. For diagnosing unused captures, they can be treated as the same. However we are not generating diagnoses within dependent contexts right now (L1524), so this is not really related to this fix.
It looks like clang stops warning about the unnecessary capture in the following code when this patch is applied:

```
void foo2(int);

void foo1() {
  const int c = 10;
  auto lambda1 = [c](auto a) { // clang used to issue warning "lambda capture 'c' is not required to be captured for this use"
    foo2(c);
  };
  lambda1(100);
}
```

Is it possible to suppress the warning if From is an init capture instead?


Repository:
  rL LLVM

https://reviews.llvm.org/D33526





More information about the cfe-commits mailing list