From 00d66cce52cf027eac77591a9847f87dacf36995 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 21 Jan 2011 01:11:43 +0000 Subject: [PATCH] Add more reference-binding examples from the C++0x working paper, all of which seem to be working fine git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123955 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../dcl.decl/dcl.init/dcl.init.ref/p5-0x.cpp | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-0x.cpp b/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-0x.cpp index fe67d8a917..6f81326b1d 100644 --- a/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-0x.cpp +++ b/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-0x.cpp @@ -89,7 +89,23 @@ void test_direct_binding() { const NonCopyable &nc11 = ConvertsTo(); } -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(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; } + -- 2.40.0