]> granicus.if.org Git - clang/commitdiff
Add more reference-binding examples from the C++0x working paper, all of which seem...
authorDouglas Gregor <dgregor@apple.com>
Fri, 21 Jan 2011 01:11:43 +0000 (01:11 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 21 Jan 2011 01:11:43 +0000 (01:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123955 91177308-0d34-0410-b5e6-96231b3b80d8

test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-0x.cpp

index fe67d8a917c55a17bb7e06108a435a1cca8d3cdc..6f81326b1d856351f86a451967dfd4004ba46d7e 100644 (file)
@@ -89,7 +89,23 @@ void test_direct_binding() {
   const NonCopyable &nc11 = ConvertsTo<NonCopyableDerived&&>();
 }
 
-namespace std_example {
+namespace std_example_1 {
+  double d = 2.0; 
+  double& rd = d; 
+  const double& rcd = d;
+  struct A { }; 
+  struct B : A { 
+    operator int&();
+  } b;
+  A& ra = b; 
+  const A& rca = b; 
+  int& ir = B();
+}
+
+namespace std_example_2 {
+  double& rd2 = 2.0; // expected-error{{non-const lvalue reference to type 'double' cannot bind to a temporary of type 'double'}}
+  int i = 2; 
+  double& rd3 = i; // expected-error{{non-const lvalue reference to type 'double' cannot bind to a value of unrelated type 'int'}}
   struct A { }; 
   struct B : A { } b; 
   extern B f(); 
@@ -100,8 +116,17 @@ namespace std_example {
     operator int&(); // expected-note{{candidate function}}
   } x;
   const A& r = x;
-  int i;
   int&& rri = static_cast<int&&>(i);
   B&& rrb = x;
-  int&& rri2 = X(); // expected-error{{no viable conversion from 'std_example::X' to 'int'}}
+  int&& rri2 = X(); // expected-error{{no viable conversion from 'std_example_2::X' to 'int'}}
+
+  const double& rcd2 = 2;
+  double&& rrd = 2;
+  const volatile int cvi = 1; 
+  const int& r2 = cvi; // expected-error{{binding of reference to type 'const int' to a value of type 'const volatile int' drops qualifiers}}
+
+  double d;
+  double&& rrd2 = d; // expected-error{{rvalue reference to type 'double' cannot bind to lvalue of type 'double'}}
+  double&& rrd3 = i;
 }
+