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

Side by Side Diff: tools/clang/move_raw/tests/test-original.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 unified diff | Download patch
« no previous file with comments | « tools/clang/move_raw/tests/test-expected.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 namespace std {
6
7 // This is the move that should be flagged. Representes the unary std::move.
8 template <typename T>
9 T move(T t) {
10 return t;
11 }
12
13 // This represents the algorithm std::move, it should not be flagged.
14 template <class InputIt, class OutputIt>
15 OutputIt move(InputIt first, InputIt last, OutputIt d_first) {
16 return d_first;
17 }
18
19 } // namespace std
20
21 // This represents some non-std move. It should not be flagged.
22 template <typename T>
23 T move(T t) {
24 return t;
25 }
26
27 void Test() {
28 int x = 3;
29
30 // Should not be flagged: x is not a pointer.
31 int y = std::move(x);
32
33 int* p = &x;
34
35 // Calling std::move on a raw pointer should be flagged.
36 int* q = std::move(p);
37
38 // Calling non-std move should not be flagged.
39 q = move(p);
40 }
OLDNEW
« no previous file with comments | « tools/clang/move_raw/tests/test-expected.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698