[PATCH] D16962: clang-tidy: avoid std::bind

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 23 17:01:32 PDT 2016


alexfh added inline comments.

================
Comment at: clang-tidy/readability/AvoidStdBindCheck.cpp:46
@@ +45,3 @@
+    BindArgument B;
+    if (const auto * M = dyn_cast<MaterializeTemporaryExpr>(E)) {
+      const auto * TE = M->GetTemporaryExpr();
----------------
In LLVM style this should be `const auto *M`.
Please clang-format the file.

================
Comment at: clang-tidy/readability/AvoidStdBindCheck.cpp:48
@@ +47,3 @@
+      const auto * TE = M->GetTemporaryExpr();
+      if (dyn_cast<CallExpr>(TE))
+        B.Kind = BK_CallExpr;
----------------
Please use `isa` instead of `dyn_cast`, when you don't need the pointer returned by `dyn_cast`.

================
Comment at: clang-tidy/readability/AvoidStdBindCheck.cpp:49
@@ +48,3 @@
+      if (dyn_cast<CallExpr>(TE))
+        B.Kind = BK_CallExpr;
+      else
----------------
I'd prefer to use the conditional operator here: `B.Kind = isa<CallExpr>(TE) ? BK_CallExpr : BK_Temporary;`.

================
Comment at: clang-tidy/readability/AvoidStdBindCheck.cpp:116
@@ +115,3 @@
+  Finder->addMatcher(
+      callExpr(callee(namedDecl(isStdBind())),
+               hasArgument(0, declRefExpr(to(functionDecl().bind("f")))))
----------------
You should be able to use `hasName("std::bind")` instead.

================
Comment at: docs/clang-tidy/checks/readability-avoid-std-bind.rst:6
@@ +5,3 @@
+
+Find uses of ``std::bind``. Replace simple uses of ``std::bind`` with lambdas.
+Lambdas will use value-capture where required.
----------------
"The check finds uses of ..."

================
Comment at: docs/clang-tidy/checks/readability-avoid-std-bind.rst:9
@@ +8,3 @@
+
+Right now it only handles free functions not member functions.
+
----------------
Add a comma before "not"?

================
Comment at: docs/clang-tidy/checks/readability-avoid-std-bind.rst:11
@@ +10,3 @@
+
+Fixits are only generated for simple uses of ``std::bind``.
+
----------------
Please add an example or two of what code is flagged and what suggested fixes are.


http://reviews.llvm.org/D16962





More information about the cfe-commits mailing list