1 // RUN: clang-cc -fsyntax-only -verify -std=c++0x %s
4 typedef irr& ilr_c1; // Collapses to int&
6 typedef ilr&& ilr_c2; // Collapses to int&
17 int over2(const int&);
20 struct conv_to_not_int_rvalue {
21 operator not_int &&();
25 int &&virr1; // expected-error {{declaration of reference variable 'virr1' requires an initializer}}
27 int &&virr3 = virr2; // expected-error {{rvalue reference cannot bind to lvalue}}
29 int &&virr4 = i1; // expected-error {{rvalue reference cannot bind to lvalue}}
30 int &&virr5 = ret_irr();
31 int &&virr6 = static_cast<int&&>(i1);
32 (void)static_cast<not_int&&>(i1); // expected-error {{types are not compatible}}
35 not_int ni1 = over(0);
37 not_int ni2 = over(ret_irr());
40 not_int ni3 = over2(0);
45 conv_to_not_int_rvalue cnir;
46 not_int &&ni4 = cnir; // expected-error {{rvalue reference cannot bind to lvalue}}
47 not_int &ni5 = cnir; // expected-error{{non-const lvalue reference to type 'struct not_int' cannot be initialized with a value of type 'struct conv_to_not_int_rvalue'}}
48 not_int &&ni6 = conv_to_not_int_rvalue();
52 } catch(int&&) { // expected-error {{cannot catch exceptions by rvalue reference}}
56 int&& should_warn(int i) {
57 // FIXME: The stack address return test doesn't reason about casts.
58 return static_cast<int&&>(i); // xpected-warning {{returning reference to temporary}}
60 int&& should_not_warn(int&& i) { // But GCC 4.4 does
61 return static_cast<int&&>(i);
65 // Test the return dance. This also tests IsReturnCopyElidable.
68 MoveOnly(const MoveOnly&) = delete;
73 MoveOnly returning() {
79 MoveOnly returningNonEligible() {
83 if (0) // Copy from global can't be elided
84 return gmo; // expected-error {{incompatible type returning}}
85 else if (0) // Copy from local static can't be elided
86 return mo; // expected-error {{incompatible type returning}}
87 else if (0) // Copy from reference can't be elided
88 return r; // expected-error {{incompatible type returning}}
89 else // Construction from different type can't be elided
90 return i; // expected-error {{incompatible type returning}}