blob: 569693a49b30b7bde0ae5050d64b095c45930f3d [file] [log] [blame]
Daniel Dunbarffd408a2009-03-24 02:24:46 +00001// RUN: clang-cc -fsyntax-only -verify -std=c++0x %s
Sebastian Redlce6fff02009-03-16 23:22:08 +00002
3typedef int&& irr;
4typedef irr& ilr_c1; // Collapses to int&
5typedef int& ilr;
6typedef ilr&& ilr_c2; // Collapses to int&
7
8irr ret_irr() {
9 return 0;
10}
11
12struct not_int {};
13
14int over(int&);
15not_int over(int&&);
16
Douglas Gregor92334522009-03-20 20:21:37 +000017int over2(const int&);
18not_int over2(int&&);
19
20struct conv_to_not_int_rvalue {
21 operator not_int &&();
22};
23
Sebastian Redlce6fff02009-03-16 23:22:08 +000024void f() {
25 int &&virr1; // expected-error {{declaration of reference variable 'virr1' requires an initializer}}
26 int &&virr2 = 0;
Douglas Gregor92334522009-03-20 20:21:37 +000027 int &&virr3 = virr2; // expected-error {{rvalue reference cannot bind to lvalue}}
Sebastian Redlce6fff02009-03-16 23:22:08 +000028 int i1 = 0;
29 int &&virr4 = i1; // expected-error {{rvalue reference cannot bind to lvalue}}
30 int &&virr5 = ret_irr();
Sebastian Redl103c6c72009-03-22 22:30:06 +000031 int &&virr6 = static_cast<int&&>(i1);
32 (void)static_cast<not_int&&>(i1); // expected-error {{types are not compatible}}
Sebastian Redlce6fff02009-03-16 23:22:08 +000033
34 int i2 = over(i1);
35 not_int ni1 = over(0);
36 int i3 = over(virr2);
37 not_int ni2 = over(ret_irr());
38
Douglas Gregor92334522009-03-20 20:21:37 +000039 int i4 = over2(i1);
Sebastian Redldfc30332009-03-29 15:27:50 +000040 not_int ni3 = over2(0);
Douglas Gregor92334522009-03-20 20:21:37 +000041
Sebastian Redlce6fff02009-03-16 23:22:08 +000042 ilr_c1 vilr1 = i1;
43 ilr_c2 vilr2 = i1;
Douglas Gregor92334522009-03-20 20:21:37 +000044
45 conv_to_not_int_rvalue cnir;
Sebastian Redldfc30332009-03-29 15:27:50 +000046 not_int &&ni4 = cnir; // expected-error {{rvalue reference cannot bind to lvalue}}
Douglas Gregor92334522009-03-20 20:21:37 +000047 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'}}
Sebastian Redldfc30332009-03-29 15:27:50 +000048 not_int &&ni6 = conv_to_not_int_rvalue();
Sebastian Redl8a8b3512009-03-22 23:49:27 +000049
50
51 try {
52 } catch(int&&) { // expected-error {{cannot catch exceptions by rvalue reference}}
53 }
Sebastian Redlce6fff02009-03-16 23:22:08 +000054}