76 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -Wself-move -std=c++11 -verify %s2 3// definitions for std::move4namespace std {5inline namespace foo {6template <class T> struct remove_reference { typedef T type; };7template <class T> struct remove_reference<T&> { typedef T type; };8template <class T> struct remove_reference<T&&> { typedef T type; };9 10template <class T> typename remove_reference<T>::type &&move(T &&t);11}12}13 14void int_test() {15 int x = 5;16 x = std::move(x); // expected-warning{{explicitly moving}}17 (x) = std::move(x); // expected-warning{{explicitly moving}}18 19 x = static_cast<int&&>(x); // expected-warning{{explicitly moving}}20 (x) = static_cast<int&&>(x); // expected-warning{{explicitly moving}}21 22 using std::move;23 x = move(x); // expected-warning{{explicitly moving}} \24 expected-warning {{unqualified call to 'std::move}}25}26 27int global;28void global_int_test() {29 global = std::move(global); // expected-warning{{explicitly moving}}30 (global) = std::move(global); // expected-warning{{explicitly moving}}31 32 global = static_cast<int&&>(global); // expected-warning{{explicitly moving}}33 (global) = static_cast<int&&>(global); // expected-warning{{explicitly moving}}34 35 using std::move;36 global = move(global); // expected-warning{{explicitly moving}} \37 expected-warning {{unqualified call to 'std::move}}38}39 40class field_test {41 int x;42 field_test(field_test&& other) {43 x = std::move(x); // expected-warning{{explicitly moving}}44 x = static_cast<int&&>(x); // expected-warning{{explicitly moving}}45 x = std::move(other.x);46 x = static_cast<int&&>(other.x);47 other.x = std::move(x);48 other.x = static_cast<int&&>(x);49 other.x = std::move(other.x); // expected-warning{{explicitly moving}}50 other.x = static_cast<int&&>(other.x); // expected-warning{{explicitly moving}}51 }52 void withSuggest(int x) {53 x = static_cast<int&&>(x); // expected-warning{{explicitly moving variable of type 'int' to itself; did you mean to move to member 'x'?}}54 x = std::move(x); // expected-warning{{explicitly moving variable of type 'int' to itself; did you mean to move to member 'x'?}}55 }56};57 58struct A {};59struct B { A a; };60struct C { C() {}; ~C() {} };61void struct_test() {62 A a;63 a = std::move(a); // expected-warning{{explicitly moving}}64 a = static_cast<A&&>(a); // expected-warning{{explicitly moving}}65 66 B b;67 b = std::move(b); // expected-warning{{explicitly moving}}68 b = static_cast<B&&>(b); // expected-warning{{explicitly moving}}69 b.a = std::move(b.a); // expected-warning{{explicitly moving}}70 b.a = static_cast<A&&>(b.a); // expected-warning{{explicitly moving}}71 72 C c;73 c = std::move(c); // expected-warning{{explicitly moving}}74 c = static_cast<C&&>(c); // expected-warning{{explicitly moving}}75}76