Implement initialization of a reference (C++ [dcl.init.ref]) as part
of copy initialization. Other pieces of the puzzle:

  - Try/Perform-ImplicitConversion now handles implicit conversions
    that don't involve references.
  - Try/Perform-CopyInitialization uses
    CheckSingleAssignmentConstraints for C. PerformCopyInitialization
    is now used for all argument passing and returning values from a
    function.
  - Diagnose errors with declaring references and const values without
    an initializer. (Uses a new Action callback, ActOnUninitializedDecl).
  
We do not yet have implicit conversion sequences for reference
binding, which means that we don't have any overloading support for
reference parameters yet.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58353 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/Parser/cxx-reference.cpp b/test/Parser/cxx-reference.cpp
index 4f3b58c..8d65def 100644
--- a/test/Parser/cxx-reference.cpp
+++ b/test/Parser/cxx-reference.cpp
@@ -3,6 +3,8 @@
 extern char *bork;
 char *& bar = bork;
 
+int val;
+
 void foo(int &a) {
 }
 
@@ -11,7 +13,7 @@
 void g(const A aref) {
 }
 
-int & const X; // expected-error {{'const' qualifier may not be applied to a reference}}
-int & volatile Y; // expected-error {{'volatile' qualifier may not be applied to a reference}}
-int & const volatile Z; /* expected-error {{'const' qualifier may not be applied}} \
+int & const X = val; // expected-error {{'const' qualifier may not be applied to a reference}}
+int & volatile Y = val; // expected-error {{'volatile' qualifier may not be applied to a reference}}
+int & const volatile Z = val; /* expected-error {{'const' qualifier may not be applied}} \
                            expected-error {{'volatile' qualifier may not be applied}} */
diff --git a/test/SemaCXX/overload-call.cpp b/test/SemaCXX/overload-call.cpp
index 1bd6496..663474d 100644
--- a/test/SemaCXX/overload-call.cpp
+++ b/test/SemaCXX/overload-call.cpp
@@ -214,3 +214,14 @@
 
   char* d8 = derived3(d);
 }
+
+// Test overloading of references. 
+// (FIXME: tests binding to determine candidate sets, not overload 
+//  resolution per se).
+int* intref(int&);
+float* intref(const int&);
+
+void intref_test() {
+  float* ir1 = intref(5);
+  float* ir2 = intref(5.5);
+}
diff --git a/test/SemaCXX/references.cpp b/test/SemaCXX/references.cpp
index 3637573..eebc3e8 100644
--- a/test/SemaCXX/references.cpp
+++ b/test/SemaCXX/references.cpp
@@ -1,4 +1,4 @@
-// RUN: clang -fsyntax-only %s
+// RUN: clang -fsyntax-only -verify %s
 int g(int);
 
 void f() {
@@ -7,10 +7,10 @@
   r = 1;
   int *p = &r;
   int &rr = r;
-  int (&rg)(int) = g;
+  int (&rg)(int) = g; // expected-warning{{statement was disambiguated as declaration}}
   rg(i);
   int a[3];
-  int (&ra)[3] = a;
+  int (&ra)[3] = a;  // expected-warning{{statement was disambiguated as declaration}}
   ra[1] = i;
   int *Q;
   int *& P = Q;
@@ -24,5 +24,57 @@
 
 
     int c[3];
-    int (&rc)[3] = c;
+    int (&rc)[3] = c; // expected-warning{{statement was disambiguated as declaration}}
+}
+
+// C++ [dcl.init.ref]p5b1
+struct A { };
+struct B : A { } b;
+
+void test3() {
+  double d = 2.0;
+  double& rd = d; // rd refers to d
+  const double& rcd = d; // rcd refers to d
+
+  A& ra = b; // ra refers to A subobject in b
+  const A& rca = b; // rca refers to A subobject in b
+}
+
+B fB();
+
+// C++ [dcl.init.ref]p5b2
+void test4() {
+  double& rd2 = 2.0; // expected-error{{non-const reference to type 'double' cannot be initialized with a temporary of type 'double'}}
+  int i = 2;
+  double& rd3 = i; // expected-error{{non-const reference to type 'double' cannot be initialized with a value of type 'int'}}
+
+  const A& rca = fB();
+}
+
+void test5() {
+  const double& rcd2 = 2; // rcd2 refers to temporary with value 2.0
+  const volatile int cvi = 1;
+  const int& r = cvi; // expected-error{{initialization of reference to type 'int const' with a value of type 'int const volatile' drops qualifiers}}
+}
+
+// C++ [dcl.init.ref]p3
+int& test6(int& x) {
+  int& yo; // expected-error{{declaration of reference variable 'yo' requires an initializer}}
+
+
+  const int val; // expected-error{{declaration of const variable 'val' requires an initializer}}
+
+  return x;
+}
+int& not_initialized_error; // expected-error{{declaration of reference variable 'not_initialized_error' requires an initializer}}
+extern int& not_initialized_okay;
+
+class Test6 {
+  int& okay;
+};
+
+struct C : B, A { };
+
+void test7(C& c) {
+  A& a1 = c; // expected-error {{ambiguous conversion from derived class 'struct C' to base class 'struct A':}}
 }