[PATCH] D52281: [clang-tidy] Add modernize check to use std::invoke in generic code

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 3 12:02:59 PDT 2018


aaron.ballman added inline comments.


================
Comment at: clang-tidy/modernize/ReplaceGenericFunctorCallCheck.cpp:32
+  //   ::std::invoke(func, 1)
+  Finder->addMatcher(callExpr(has(declRefExpr())).bind("functor"), this);
+
----------------
I don't think this will work for calls wrapped in parens or with spurious dereferences.
```
void f(int) {}

int main() {
  void (*fp)(int) = f;

  fp(12);
  (fp)(12);
  (*fp)(12);
}
```
It seems like all of those can be replaced by `std::invoke()` directly.


================
Comment at: clang-tidy/modernize/ReplaceGenericFunctorCallCheck.cpp:97
+             Functor->getSourceRange(),
+             (Twine("::std::invoke(") + Param +
+              (Functor->getNumArgs() == 0 ? "" : ", ") + OriginalParams)
----------------
You might be able to get rid of the explicit `Twine` construction here now that `Param` is a `Twine`. I could be remembering wrong though.


https://reviews.llvm.org/D52281





More information about the cfe-commits mailing list