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