summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/clang-tidy/misc-move-const-arg.cpp
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2016-04-26 19:33:49 +0000
committerAlexander Kornienko <alexfh@google.com>2016-04-26 19:33:49 +0000
commit900cadd3adb495c08c548b609d530ad3fea9b3e6 (patch)
treefcac681a79474483b4b4d995a287df5dbaf598ae /clang-tools-extra/test/clang-tidy/misc-move-const-arg.cpp
parent8dc9dcaeaccd3be047740b1f19c4beee33b0f44e (diff)
downloadbcm5719-llvm-900cadd3adb495c08c548b609d530ad3fea9b3e6.tar.gz
bcm5719-llvm-900cadd3adb495c08c548b609d530ad3fea9b3e6.zip
[clang-tidy] Now adding correct misc-move-const-arg documentation ;]
+ brushed the code a bit and renamed the test file to match the check name llvm-svn: 267592
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/misc-move-const-arg.cpp')
-rw-r--r--clang-tools-extra/test/clang-tidy/misc-move-const-arg.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-tidy/misc-move-const-arg.cpp b/clang-tools-extra/test/clang-tidy/misc-move-const-arg.cpp
new file mode 100644
index 00000000000..beb4078bdbe
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/misc-move-const-arg.cpp
@@ -0,0 +1,73 @@
+// RUN: %check_clang_tidy %s misc-move-const-arg %t
+
+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 a 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 a 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 a 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);
+}
OpenPOWER on IntegriCloud