[clang-tools-extra] r353389 - [clang-tidy] Fixed a std::bind() transformation
Jonas Toth via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 7 03:01:00 PST 2019
Author: jonastoth
Date: Thu Feb 7 03:00:59 2019
New Revision: 353389
URL: http://llvm.org/viewvc/llvm-project?rev=353389&view=rev
Log:
[clang-tidy] Fixed a std::bind() transformation
There was an extra semicolon that was somehow working in some contexts.
Patch by oleg.smolsky.
Modified:
clang-tools-extra/trunk/clang-tidy/modernize/AvoidBindCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-avoid-bind.cpp
Modified: clang-tools-extra/trunk/clang-tidy/modernize/AvoidBindCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/AvoidBindCheck.cpp?rev=353389&r1=353388&r2=353389&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/AvoidBindCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/AvoidBindCheck.cpp Thu Feb 7 03:00:59 2019
@@ -169,7 +169,7 @@ void AvoidBindCheck::check(const MatchFi
Ref->printPretty(Stream, nullptr, Result.Context->getPrintingPolicy());
Stream << "(";
addFunctionCallArgs(Args, Stream);
- Stream << "); };";
+ Stream << "); }";
Diag << FixItHint::CreateReplacement(MatchedDecl->getSourceRange(),
Stream.str());
Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-avoid-bind.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-avoid-bind.cpp?rev=353389&r1=353388&r2=353389&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-avoid-bind.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-avoid-bind.cpp Thu Feb 7 03:00:59 2019
@@ -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 <typename _Tp>
+_Tp declval();
+
+template <typename _Functor, typename... _ArgTypes>
+struct __res {
+ template <typename... _Args>
+ static decltype(declval<_Functor>()(_Args()...)) _S_test(int);
+
+ template <typename...>
+ static void _S_test(...);
+
+ using type = decltype(_S_test<_ArgTypes...>(0));
+};
+
+template <typename>
+struct function;
+
+template <typename... _ArgTypes>
+struct function<void(_ArgTypes...)> {
+ template <typename _Functor,
+ typename = typename __res<_Functor, _ArgTypes...>::type>
+ function(_Functor) {}
+};
+} // namespace std
+
+struct Thing {};
+void UseThing(Thing *);
+
+struct Callback {
+ Callback();
+ Callback(std::function<void()>);
+ void Reset(std::function<void()>);
+};
+
+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); });
+}
More information about the cfe-commits
mailing list