2008-07-06 Kai Tietz <kai.tietz@onevision.com>
[official-gcc.git] / gcc / testsuite / g++.dg / cpp0x / elision.C
blob35d5e4b02fb4dc827592440ef1aae93ae70df097
1 // I, Howard Hinnant, hereby place this code in the public domain.
3 // Test: Implicit cast to rvalue when eliding copy
5 // { dg-do compile }
6 // { dg-options "-std=c++0x" }
8 template <bool> struct sa;
9 template <> struct sa<true> {};
11 struct one   {char x[1];};
12 struct two   {char x[2];};
14 class move_only
16     move_only(const move_only&);
17     move_only& operator=(const move_only&);
18 public:
19     move_only() {}
20     move_only(move_only&&) {}
21     move_only& operator=(move_only&&) {return *this;}
24 move_only
25 test1()
27     return move_only();
30 move_only
31 test2()
33     move_only x;
34     return x;
37 move_only
38 test3(bool b)
40     move_only x1;
41     if (b)
42     {
43         move_only x2;
44         return x2;
45     }
46     return x1;
49 void
50 test4(bool b)
52     if (!b)
53         throw move_only();
56 void
57 test5(bool b)
59     move_only x;
60     if (!b)
61         throw x;
64 extern bool b;
66 int main()
68     move_only t1 = test1();
69     move_only t2 = test2();
70     move_only t3 = test3(b);
71     test4(b);
72     test5(b);
73     return 0;
76 bool b = true;