diff --git a/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp b/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp index 44174243c6c8..c51b6e86b3f6 100644 --- a/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp @@ -169,7 +169,7 @@ void AvoidBindCheck::check(const MatchFinder::MatchResult &Result) { Ref->printPretty(Stream, nullptr, Result.Context->getPrintingPolicy()); Stream << "("; addFunctionCallArgs(Args, Stream); - Stream << "); };"; + Stream << "); }"; Diag << FixItHint::CreateReplacement(MatchedDecl->getSourceRange(), Stream.str()); diff --git a/clang-tools-extra/test/clang-tidy/modernize-avoid-bind.cpp b/clang-tools-extra/test/clang-tidy/modernize-avoid-bind.cpp index 1c78b9e63056..721801bef11d 100644 --- a/clang-tools-extra/test/clang-tidy/modernize-avoid-bind.cpp +++ b/clang-tools-extra/test/clang-tidy/modernize-avoid-bind.cpp @@ -77,3 +77,47 @@ void n() { // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind // CHECK-FIXES: auto clj = [] { return C::add(1, 1); }; } + +// Let's fake a minimal std::function-like facility. +namespace std { +template +_Tp declval(); + +template +struct __res { + template + static decltype(declval<_Functor>()(_Args()...)) _S_test(int); + + template + static void _S_test(...); + + using type = decltype(_S_test<_ArgTypes...>(0)); +}; + +template +struct function; + +template +struct function { + template ::type> + function(_Functor) {} +}; +} // namespace std + +struct Thing {}; +void UseThing(Thing *); + +struct Callback { + Callback(); + Callback(std::function); + void Reset(std::function); +}; + +void test(Thing *t) { + Callback cb; + if (t) + cb.Reset(std::bind(UseThing, t)); + // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind + // CHECK-FIXES: cb.Reset([=] { return UseThing(t); }); +}