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