[PATCH] D44844: [PR36880] Avoid -Wunused-lambda-capture false positive for explicit this capture used in an unresolved member in a generic lambda

Alex Lorenz via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 23 16:09:57 PDT 2018


arphaman added inline comments.


================
Comment at: lib/Sema/TreeTransform.h:11269
+    // 'this' capture is marked as 'used'.
+    if (Old->isImplicitCXXThisAccess())
+      getSema().CheckCXXThisCapture(Old->getMemberNameInfo().getLoc(),
----------------
efriedma wrote:
> This doesn't make sense; in general, you can't tell whether an UnresolvedMemberExpr requires a "this" capture.
> 
> ```
> template<typename T> class C : T {
> static int f(int);
> int f(double);
> public:
> int g() {
>   return []{ return f(T::x); }();
> }
> };
> 
> struct A { static int x; };
> void x(C<A> c) { c.g(); }
> ```
Good point, we still emit a false positive warning for 

```
template <class T> struct DummyTemplate {
  template <class T2> void methodTemplate(const T2 &) {}
  static void methodTemplate(float *) { }

  void ToTemplate(const int &param) {
    [this](const auto &p) { methodTemplate(p); }(param); // incorrect warning!
  }
};

void main() {
  int i = 0;
  DummyTemplate<bool> dt;
  dt.ToTemplate(i);
}
```

I will work on a better fix.


Repository:
  rC Clang

https://reviews.llvm.org/D44844





More information about the cfe-commits mailing list