c++: Tweaks for -Wredundant-move [PR107363]
[official-gcc.git] / gcc / testsuite / g++.dg / cpp0x / Wredundant-move13.C
blob80e7d80cd029a4fb4e01c6ff66dd289c760f9ccf
1 // PR c++/107363
2 // { dg-do compile { target c++11 } }
3 // { dg-options "-Wredundant-move" }
5 // Define std::move.
6 namespace std {
7   template<typename _Tp>
8     struct remove_reference
9     { typedef _Tp   type; };
11   template<typename _Tp>
12     struct remove_reference<_Tp&>
13     { typedef _Tp   type; };
15   template<typename _Tp>
16     struct remove_reference<_Tp&&>
17     { typedef _Tp   type; };
19   template<typename _Tp>
20     constexpr typename std::remove_reference<_Tp>::type&&
21     move(_Tp&& __t) noexcept
22     { return static_cast<typename std::remove_reference<_Tp>::type&&>(__t); }
25 template <typename T, typename U>
26 struct Optional {
27   U &value();
28   T release_value() {
29     T t = std::move (value ());
30     return t;
31   }
34 struct Foo {};
35 void test(Optional<const Foo, const Foo> o) { o.release_value(); }
37 struct F {
38   F(const F&);
39   F(F&&) = delete;
42 struct Z {
43   Z(const Z&) = delete;
44   Z(Z&&) = delete;
45   Z(const Z&&);
48 const F& constfref();
49 const Z& constzref();
51 void
52 g ()
54   // Will call F::F(const F&) w/ and w/o std::move.  So it's redundant.
55   F f = std::move (constfref()); // { dg-warning "redundant move in initialization" }
56   (void) f;
57   // Will call Z::Z(const Z&&) w/ std::move, and Z::Z(const Z&) w/o.
58   // So it's not redundant.
59   Z z = std::move (constzref());
60   (void) z;