Douglas Gregor | 81c2915 | 2008-10-29 00:13:59 +0000 | [diff] [blame] | 1 | // RUN: clang -fsyntax-only -verify %s |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 2 | int g(int); |
| 3 | |
| 4 | void f() { |
| 5 | int i; |
| 6 | int &r = i; |
| 7 | r = 1; |
| 8 | int *p = &r; |
| 9 | int &rr = r; |
Douglas Gregor | 81c2915 | 2008-10-29 00:13:59 +0000 | [diff] [blame] | 10 | int (&rg)(int) = g; // expected-warning{{statement was disambiguated as declaration}} |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 11 | rg(i); |
| 12 | int a[3]; |
Douglas Gregor | 81c2915 | 2008-10-29 00:13:59 +0000 | [diff] [blame] | 13 | int (&ra)[3] = a; // expected-warning{{statement was disambiguated as declaration}} |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 14 | ra[1] = i; |
| 15 | int *Q; |
| 16 | int *& P = Q; |
| 17 | P[1] = 1; |
| 18 | } |
Chris Lattner | 2806720 | 2007-09-04 16:49:09 +0000 | [diff] [blame] | 19 | |
Chris Lattner | 5f505bf | 2007-10-16 02:55:40 +0000 | [diff] [blame] | 20 | typedef int t[1]; |
| 21 | void test2() { |
| 22 | t a; |
| 23 | t& b = a; |
| 24 | |
| 25 | |
| 26 | int c[3]; |
Douglas Gregor | 81c2915 | 2008-10-29 00:13:59 +0000 | [diff] [blame] | 27 | int (&rc)[3] = c; // expected-warning{{statement was disambiguated as declaration}} |
| 28 | } |
| 29 | |
| 30 | // C++ [dcl.init.ref]p5b1 |
| 31 | struct A { }; |
| 32 | struct B : A { } b; |
| 33 | |
| 34 | void test3() { |
| 35 | double d = 2.0; |
| 36 | double& rd = d; // rd refers to d |
| 37 | const double& rcd = d; // rcd refers to d |
| 38 | |
| 39 | A& ra = b; // ra refers to A subobject in b |
| 40 | const A& rca = b; // rca refers to A subobject in b |
| 41 | } |
| 42 | |
| 43 | B fB(); |
| 44 | |
| 45 | // C++ [dcl.init.ref]p5b2 |
| 46 | void test4() { |
| 47 | double& rd2 = 2.0; // expected-error{{non-const reference to type 'double' cannot be initialized with a temporary of type 'double'}} |
| 48 | int i = 2; |
| 49 | double& rd3 = i; // expected-error{{non-const reference to type 'double' cannot be initialized with a value of type 'int'}} |
| 50 | |
| 51 | const A& rca = fB(); |
| 52 | } |
| 53 | |
| 54 | void test5() { |
| 55 | const double& rcd2 = 2; // rcd2 refers to temporary with value 2.0 |
| 56 | const volatile int cvi = 1; |
| 57 | const int& r = cvi; // expected-error{{initialization of reference to type 'int const' with a value of type 'int const volatile' drops qualifiers}} |
| 58 | } |
| 59 | |
| 60 | // C++ [dcl.init.ref]p3 |
| 61 | int& test6(int& x) { |
| 62 | int& yo; // expected-error{{declaration of reference variable 'yo' requires an initializer}} |
| 63 | |
Douglas Gregor | 81c2915 | 2008-10-29 00:13:59 +0000 | [diff] [blame] | 64 | return x; |
| 65 | } |
| 66 | int& not_initialized_error; // expected-error{{declaration of reference variable 'not_initialized_error' requires an initializer}} |
| 67 | extern int& not_initialized_okay; |
| 68 | |
| 69 | class Test6 { |
| 70 | int& okay; |
| 71 | }; |
| 72 | |
| 73 | struct C : B, A { }; |
| 74 | |
| 75 | void test7(C& c) { |
| 76 | A& a1 = c; // expected-error {{ambiguous conversion from derived class 'struct C' to base class 'struct A':}} |
Chris Lattner | 5f505bf | 2007-10-16 02:55:40 +0000 | [diff] [blame] | 77 | } |