1 // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 %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 to type 'int' cannot bind to lvalue of type 'int'}}
35 int &&virr4
= i1
; // expected-error {{rvalue reference to type 'int' cannot bind to lvalue of type 'int'}}
36 int &&virr5
= ret_irr();
37 int &&virr6
= static_cast<int&&>(i1
);
38 (void)static_cast<not_int
&&>(i1
); // expected-error {{reference to type 'not_int' could not bind to an lvalue of type 'int'}}
39 (void)static_cast<int &&>(static_cast<int const&&>(i1
)); // expected-error {{cannot cast from rvalue of type 'const int' to rvalue reference type 'int &&'}}
40 (void)static_cast<int &&>(ci1
); // expected-error {{types are not compatible}}
41 (void)static_cast<int &&>(d1
);
43 not_int ni1
= over(0);
45 not_int ni2
= over(ret_irr());
48 not_int ni3
= over2(0);
53 conv_to_not_int_rvalue cnir
;
55 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'}}
56 not_int
&&ni6
= conv_to_not_int_rvalue();
58 fun_type
&&fun_ref
= fun
; // works because functions are special
59 fun_type
&&fun_ref2
= make_fun(); // same
60 fun_type
&fun_lref
= make_fun(); // also special
63 } catch(int&&) { // expected-error {{cannot catch exceptions by rvalue reference}}
67 int&& should_warn(int i
) {
68 return static_cast<int&&>(i
); // expected-warning {{reference to stack memory associated with parameter 'i' returned}}
70 int&& should_not_warn(int&& i
) {
71 return static_cast<int&&>(i
);
75 // Test the return dance. This also tests IsReturnCopyElidable.
78 MoveOnly(const MoveOnly
&) = delete; // expected-note 3{{explicitly marked deleted here}}
82 MoveOnly
returningNonEligible() {
85 if (0) // Copy from global can't be elided
86 return gmo
; // expected-error {{call to deleted constructor}}
87 else if (0) // Copy from local static can't be elided
88 return mo
; // expected-error {{call to deleted constructor}}
89 else // Copy from reference can't be elided
90 return r
; // expected-error {{call to deleted constructor}}