return;
Finder->addMatcher(
- callExpr(callee(namedDecl(hasName("::std::bind"))),
- hasArgument(0, declRefExpr(to(functionDecl().bind("f")))))
+ callExpr(
+ callee(namedDecl(hasName("::std::bind"))),
+ hasArgument(0, declRefExpr(to(functionDecl().bind("f"))).bind("ref")))
.bind("bind"),
this);
}
bool HasCapturedArgument = llvm::any_of(
Args, [](const BindArgument &B) { return B.Kind == BK_Other; });
-
+ const auto *Ref = Result.Nodes.getNodeAs<DeclRefExpr>("ref");
Stream << "[" << (HasCapturedArgument ? "=" : "") << "]";
addPlaceholderArgs(Args, Stream);
- Stream << " { return " << F->getName() << "(";
+ Stream << " { return ";
+ Ref->printPretty(Stream, nullptr, Result.Context->getPrintingPolicy());
+ Stream<< "(";
addFunctionCallArgs(Args, Stream);
Stream << "); };";
- Diag << FixItHint::CreateReplacement(MatchedDecl->getSourceRange(), Stream.str());
+ Diag << FixItHint::CreateReplacement(MatchedDecl->getSourceRange(),
+ Stream.str());
}
} // namespace modernize
// CHECK-FIXES: auto clj = std::bind(add, 1, add(2, 5));
}
+namespace C {
+ int add(int x, int y){ return x + y; }
+}
+
+void n() {
+ auto clj = std::bind(C::add, 1, 1);
+ // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind
+ // CHECK-FIXES: auto clj = [] { return C::add(1, 1); };
+}