1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s
4 typedef irr
& ilr_c1
; // Collapses to int&
6 typedef ilr
&& ilr_c2
; // Collapses to int&
9 return 0; // expected-warning {{returning reference to local temporary}}
17 int over2(const int&);
20 struct conv_to_not_int_rvalue
{
21 operator not_int
&&();
24 typedef void (fun_type
)();
26 fun_type
&&make_fun();
29 int &&virr1
; // expected-error {{declaration of reference variable 'virr1' requires an initializer}}
31 int &&virr3
= virr2
; // expected-error {{rvalue reference cannot bind to lvalue}}
33 int &&virr4
= i1
; // expected-error {{rvalue reference cannot bind to lvalue}}
34 int &&virr5
= ret_irr();
35 int &&virr6
= static_cast<int&&>(i1
);
36 (void)static_cast<not_int
&&>(i1
); // expected-error {{types are not compatible}}
39 not_int ni1
= over(0);
41 not_int ni2
= over(ret_irr());
44 not_int ni3
= over2(0);
49 conv_to_not_int_rvalue cnir
;
50 not_int
&&ni4
= cnir
; // expected-error {{rvalue reference cannot bind to lvalue}}
51 not_int
&ni5
= cnir
; // expected-error{{non-const lvalue reference to type 'not_int' cannot bind to a value of unrelated type 'conv_to_not_int_rvalue'}}
52 not_int
&&ni6
= conv_to_not_int_rvalue();
54 fun_type
&&fun_ref
= fun
; // works because functions are special
55 fun_type
&&fun_ref2
= make_fun(); // same
56 fun_type
&fun_lref
= make_fun(); // also special
59 } catch(int&&) { // expected-error {{cannot catch exceptions by rvalue reference}}
63 int&& should_warn(int i
) {
64 // FIXME: The stack address return test doesn't reason about casts.
65 return static_cast<int&&>(i
); // xpected-warning {{returning reference to temporary}}
67 int&& should_not_warn(int&& i
) { // But GCC 4.4 does
68 return static_cast<int&&>(i
);
72 // Test the return dance. This also tests IsReturnCopyElidable.
75 MoveOnly(const MoveOnly
&) = delete; // expected-note {{candidate constructor}} \
76 // expected-note 3{{explicitly marked deleted here}}
77 MoveOnly(MoveOnly
&&); // expected-note {{candidate constructor}}
78 MoveOnly(int&&); // expected-note {{candidate constructor}}
82 MoveOnly
returningNonEligible() {
86 if (0) // Copy from global can't be elided
87 return gmo
; // expected-error {{call to deleted constructor}}
88 else if (0) // Copy from local static can't be elided
89 return mo
; // expected-error {{call to deleted constructor}}
90 else if (0) // Copy from reference can't be elided
91 return r
; // expected-error {{call to deleted constructor}}
92 else // Construction from different type can't be elided
93 return i
; // expected-error {{no viable conversion from 'int' to 'MoveOnly'}}