Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / SemaCXX / warn-self-move.cpp
blob0987e9b6bf6017c8134829eb6c4681819322f075
1 // RUN: %clang_cc1 -fsyntax-only -Wself-move -std=c++11 -verify %s
3 // definitions for std::move
4 namespace std {
5 inline namespace foo {
6 template <class T> struct remove_reference { typedef T type; };
7 template <class T> struct remove_reference<T&> { typedef T type; };
8 template <class T> struct remove_reference<T&&> { typedef T type; };
10 template <class T> typename remove_reference<T>::type &&move(T &&t);
14 void int_test() {
15 int x = 5;
16 x = std::move(x); // expected-warning{{explicitly moving}}
17 (x) = std::move(x); // expected-warning{{explicitly moving}}
19 using std::move;
20 x = move(x); // expected-warning{{explicitly moving}} \
21 expected-warning {{unqualified call to 'std::move}}
24 int global;
25 void global_int_test() {
26 global = std::move(global); // expected-warning{{explicitly moving}}
27 (global) = std::move(global); // expected-warning{{explicitly moving}}
29 using std::move;
30 global = move(global); // expected-warning{{explicitly moving}} \
31 expected-warning {{unqualified call to 'std::move}}
34 class field_test {
35 int x;
36 field_test(field_test&& other) {
37 x = std::move(x); // expected-warning{{explicitly moving}}
38 x = std::move(other.x);
39 other.x = std::move(x);
40 other.x = std::move(other.x); // expected-warning{{explicitly moving}}
42 void withSuggest(int x) {
43 x = std::move(x); // expected-warning{{explicitly moving variable of type 'int' to itself; did you mean to move to member 'x'?}}
47 struct A {};
48 struct B { A a; };
49 struct C { C() {}; ~C() {} };
50 void struct_test() {
51 A a;
52 a = std::move(a); // expected-warning{{explicitly moving}}
54 B b;
55 b = std::move(b); // expected-warning{{explicitly moving}}
56 b.a = std::move(b.a); // expected-warning{{explicitly moving}}
58 C c;
59 c = std::move(c); // expected-warning{{explicitly moving}}