1 // I, Howard Hinnant, hereby place this code in the public domain.
2 
3 // Test: Implicit cast to rvalue when eliding copy
4 
5 // { dg-do compile { target c++11 } }
6 
7 template <bool> struct sa;
8 template <> struct sa<true> {};
9 
10 struct one   {char x[1];};
11 struct two   {char x[2];};
12 
13 class move_only
14 {
15     move_only(const move_only&); // { dg-message "private" }
16     move_only& operator=(const move_only&);
17 public:
18     move_only() {}
19     move_only(move_only&&) {}
20     move_only& operator=(move_only&&) {return *this;}
21 };
22 
23 move_only
24 test1()
25 {
26     static move_only x;
27     return x;  //  { dg-error "within this context" }
28 }
29 
30 move_only
31 test2(move_only&& x)
32 {
33     return x;  //  { dg-error "within this context" "" { target c++17_down } }
34 }
35 
36 int main()
37 {
38     move_only t1 = test1();
39     move_only t2 = test2(move_only());
40     return 0;
41 }
42 
43 bool b = true;
44