diff options
author | Alexander Kornienko <alexfh@google.com> | 2015-11-25 15:56:11 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2015-11-25 15:56:11 +0000 |
commit | e4ac60d7bc115089fe78e29c304aa2fe4cb13f02 (patch) | |
tree | bbe0ed105951fa6b34858406f20a67a70dd02487 /clang-tools-extra/test/clang-tidy/move-const-arg.cpp | |
parent | 25150784ae5013c34a6bc0eb7d180e08835cf297 (diff) | |
download | bcm5719-llvm-e4ac60d7bc115089fe78e29c304aa2fe4cb13f02.tar.gz bcm5719-llvm-e4ac60d7bc115089fe78e29c304aa2fe4cb13f02.zip |
[clang-tidy] Const std::move() argument ClangTidy check
ClangTidy check for finding cases when std::move() is called with const or
trivially copyable arguments, that doesn't lead to any move or argument but it
makes copy. FixIt generates patch for removing call of std::move().
Patch by Vadym Doroshenko! (+ a couple of minor fixes)
Differential Revision: http://reviews.llvm.org/D12031
llvm-svn: 254070
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/move-const-arg.cpp')
-rw-r--r-- | clang-tools-extra/test/clang-tidy/move-const-arg.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-tidy/move-const-arg.cpp b/clang-tools-extra/test/clang-tidy/move-const-arg.cpp new file mode 100644 index 00000000000..015c1a39049 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/move-const-arg.cpp @@ -0,0 +1,73 @@ +// RUN: %check_clang_tidy %s misc-move-const-arg %t -- -- -std=c++11 + +namespace std { +template <typename> struct remove_reference; + +template <typename _Tp> struct remove_reference { typedef _Tp type; }; + +template <typename _Tp> struct remove_reference<_Tp &> { typedef _Tp type; }; + +template <typename _Tp> struct remove_reference<_Tp &&> { typedef _Tp type; }; + +template <typename _Tp> +constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t); + +} // namespace std + +class A { +public: + A() {} + A(const A &rhs) {} + A(A &&rhs) {} +}; + +int f1() { + return std::move(42); + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the expression of trivially-copyable type has no effect; remove std::move() [misc-move-const-arg] + // CHECK-FIXES: return 42; +} + +int f2(int x2) { + return std::move(x2); + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the variable of trivially-copyable type + // CHECK-FIXES: return x2; +} + +int *f3(int *x3) { + return std::move(x3); + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the variable of trivially-copyable type + // CHECK-FIXES: return x3; +} + +A f4(A x4) { return std::move(x4); } + +A f5(const A x5) { + return std::move(x5); + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable + // CHECK-FIXES: return x5; +} + +template <typename T> T f6(const T x6) { return std::move(x6); } + +void f7() { int a = f6(10); } + +#define M1(x) x +void f8() { + const A a; + M1(A b = std::move(a);) + // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: std::move of the const variable + // CHECK-FIXES: M1(A b = a;) +} + +#define M2(x) std::move(x) +int f9() { return M2(1); } + +template <typename T> T f10(const int x10) { + return std::move(x10); + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable + // CHECK-FIXES: return x10; +} +void f11() { + f10<int>(1); + f10<double>(1); +} |