Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Unified Diff: tools/clang/move_raw/tests/test-expected.cc

Issue 2919243002: Add a clang tool to detect std::move(raw ptr) (Closed)
Patch Set: Add a TODO to make this a clang-tidy check Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/clang/move_raw/MoveRaw.cpp ('k') | tools/clang/move_raw/tests/test-original.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/clang/move_raw/tests/test-expected.cc
diff --git a/tools/clang/move_raw/tests/test-expected.cc b/tools/clang/move_raw/tests/test-expected.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1432d33a91f16ee6a3bf5cea44a736df046e6c19
--- /dev/null
+++ b/tools/clang/move_raw/tests/test-expected.cc
@@ -0,0 +1,40 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+namespace std {
+
+// This is the move that should be flagged. Representes the unary std::move.
+template <typename T>
+T move(T t) {
+ return t;
+}
+
+// This represents the algorithm std::move, it should not be flagged.
+template <class InputIt, class OutputIt>
+OutputIt move(InputIt first, InputIt last, OutputIt d_first) {
+ return d_first;
+}
+
+} // namespace std
+
+// This represents some non-std move. It should not be flagged.
+template <typename T>
+T move(T t) {
+ return t;
+}
+
+void Test() {
+ int x = 3;
+
+ // Should not be flagged: x is not a pointer.
+ int y = std::move(x);
+
+ int* p = &x;
+
+ // Calling std::move on a raw pointer should be flagged.
+ int* q = /*This tries to move a raw pointer!*/ std::move(p);
+
+ // Calling non-std move should not be flagged.
+ q = move(p);
+}
« no previous file with comments | « tools/clang/move_raw/MoveRaw.cpp ('k') | tools/clang/move_raw/tests/test-original.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698