1 // PR c++/87582
2 // { dg-do run { target c++11 } }
3 // { dg-options "-Wreturn-local-addr" }
4 
5 struct S { int s, t; };
6 S v {1, 2};
7 int a[3] = {1, 2, 3};
8 
9 int &
f1()10 f1 ()
11 {
12   auto& [s, t] = v;	// { dg-warning "structured bindings only available with" "" { target c++14_down } }
13   return s;		// { dg-bogus "reference to local variable '.' returned" }
14 }
15 
16 int &
f2()17 f2 ()
18 {
19   S v {1, 2};		// { dg-warning "reference to local variable 'v' returned" }
20   auto& [s, t] = v;	// { dg-warning "structured bindings only available with" "" { target c++14_down } }
21   return s;
22 }
23 
24 int &
f3()25 f3 ()
26 {
27   auto& [s, t, u] = a;	// { dg-warning "structured bindings only available with" "" { target c++14_down } }
28   return s;		// { dg-bogus "reference to local variable '.' returned" }
29 }
30 
31 int &
f4()32 f4 ()
33 {
34   int a[3] = {1, 2, 3};	// { dg-warning "reference to local variable 'a' returned" }
35   auto& [s, t, u] = a;	// { dg-warning "structured bindings only available with" "" { target c++14_down } }
36   return s;
37 }
38 
39 int &
f5()40 f5 ()
41 {
42   auto [s, t] = v;	// { dg-warning "structured bindings only available with" "" { target c++14_down } }
43   return s;		// { dg-warning "reference to local variable 's' returned" "" { target *-*-* } .-1 }
44 }
45 
46 int &
f6()47 f6 ()
48 {
49   S v {1, 2};
50   auto [s, t] = v;	// { dg-warning "structured bindings only available with" "" { target c++14_down } }
51   return s;		// { dg-warning "reference to local variable 's' returned" "" { target *-*-* } .-1 }
52 }
53 
54 int &
f7()55 f7 ()
56 {
57   auto [s, t, u] = a;	// { dg-warning "structured bindings only available with" "" { target c++14_down } }
58   return s;		// { dg-warning "reference to local variable 's' returned" "" { target *-*-* } .-1 }
59 }
60 
61 int &
f8()62 f8 ()
63 {
64   int a[3] = {1, 2, 3};
65   auto [s, t, u] = a;	// { dg-warning "structured bindings only available with" "" { target c++14_down } }
66   return s;		// { dg-warning "reference to local variable 's' returned" "" { target *-*-* } .-1 }
67 }
68 
69 int *
f9()70 f9 ()
71 {
72   auto& [s, t] = v;	// { dg-warning "structured bindings only available with" "" { target c++14_down } }
73   return &s;		// { dg-bogus "address of local variable '.' returned" }
74 }
75 
76 int *
f10()77 f10 ()
78 {
79   S v {1, 2};		// { dg-warning "address of local variable 'v' returned" }
80   auto& [s, t] = v;	// { dg-warning "structured bindings only available with" "" { target c++14_down } }
81   return &s;
82 }
83 
84 int *
f11()85 f11 ()
86 {
87   auto& [s, t, u] = a;	// { dg-warning "structured bindings only available with" "" { target c++14_down } }
88   return &s;		// { dg-bogus "address of local variable '.' returned" }
89 }
90 
91 int *
f12()92 f12 ()
93 {
94   int a[3] = {1, 2, 3};	// { dg-warning "address of local variable 'a' returned" }
95   auto& [s, t, u] = a;	// { dg-warning "structured bindings only available with" "" { target c++14_down } }
96   return &s;
97 }
98 
99 int *
f13()100 f13 ()
101 {
102   auto [s, t] = v;	// { dg-warning "structured bindings only available with" "" { target c++14_down } }
103   return &s;		// { dg-warning "address of local variable 's' returned" "" { target *-*-* } .-1 }
104 }
105 
106 int *
f14()107 f14 ()
108 {
109   S v {1, 2};
110   auto [s, t] = v;	// { dg-warning "structured bindings only available with" "" { target c++14_down } }
111   return &s;		// { dg-warning "address of local variable 's' returned" "" { target *-*-* } .-1 }
112 }
113 
114 int *
f15()115 f15 ()
116 {
117   auto [s, t, u] = a;	// { dg-warning "structured bindings only available with" "" { target c++14_down } }
118   return &s;		// { dg-warning "address of local variable 's' returned" "" { target *-*-* } .-1 }
119 }
120 
121 int *
f16()122 f16 ()
123 {
124   int a[3] = {1, 2, 3};
125   auto [s, t, u] = a;	// { dg-warning "structured bindings only available with" "" { target c++14_down } }
126   return &s;		// { dg-warning "address of local variable 's' returned" "" { target *-*-* } .-1 }
127 }
128 
129 int
main()130 main ()
131 {
132   if (&f1 () != &v.s || &f3 () != &a[0] || f9 () != &v.s || f11 () != &a[0])
133     __builtin_abort ();
134 }
135