xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/decl-init-ref.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc struct A {};
4*f4a2713aSLionel Sambuc 
5*f4a2713aSLionel Sambuc struct BASE {
6*f4a2713aSLionel Sambuc   operator A(); // expected-note {{candidate function}}
7*f4a2713aSLionel Sambuc };
8*f4a2713aSLionel Sambuc 
9*f4a2713aSLionel Sambuc struct BASE1 {
10*f4a2713aSLionel Sambuc  operator A();  // expected-note {{candidate function}}
11*f4a2713aSLionel Sambuc };
12*f4a2713aSLionel Sambuc 
13*f4a2713aSLionel Sambuc class B : public BASE , public BASE1
14*f4a2713aSLionel Sambuc {
15*f4a2713aSLionel Sambuc   public:
16*f4a2713aSLionel Sambuc   B();
17*f4a2713aSLionel Sambuc } b;
18*f4a2713aSLionel Sambuc 
19*f4a2713aSLionel Sambuc extern B f();
20*f4a2713aSLionel Sambuc 
21*f4a2713aSLionel Sambuc const int& ri = (void)0; // expected-error {{reference to type 'const int' could not bind to an rvalue of type 'void'}}
22*f4a2713aSLionel Sambuc 
23*f4a2713aSLionel Sambuc int main() {
24*f4a2713aSLionel Sambuc         const A& rca = f(); // expected-error {{reference initialization of type 'const A &' with initializer of type 'B' is ambiguous}}
25*f4a2713aSLionel Sambuc         A& ra = f(); // expected-error {{non-const lvalue reference to type 'A' cannot bind to a temporary of type 'B'}}
26*f4a2713aSLionel Sambuc }
27*f4a2713aSLionel Sambuc 
28*f4a2713aSLionel Sambuc struct PR6139 { A (&x)[1]; };
29*f4a2713aSLionel Sambuc PR6139 x = {{A()}}; // expected-error{{non-const lvalue reference to type 'A [1]' cannot bind to an initializer list temporary}}
30*f4a2713aSLionel Sambuc 
31*f4a2713aSLionel Sambuc struct PR6139b { A (&x)[1]; };
32*f4a2713aSLionel Sambuc PR6139b y = {A()}; // expected-error{{non-const lvalue reference to type 'A [1]' cannot bind to a temporary of type 'A'}}
33*f4a2713aSLionel Sambuc 
34*f4a2713aSLionel Sambuc namespace PR16502 {
35*f4a2713aSLionel Sambuc   struct A { int &&temporary; int x, y; };
36*f4a2713aSLionel Sambuc   int f();
37*f4a2713aSLionel Sambuc   const A &c = { 10, ++c.temporary };
38*f4a2713aSLionel Sambuc }
39