| 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 & |
| 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 & |
| 17 |
f2 () |
| 18 |
{ |
| 19 |
S v {1, 2}; |
| 20 |
auto& [s, t] = v; // { dg-warning "structured bindings only available with" "" { target c++14_down } } |
| 21 |
return s; // { dg-warning "reference to local variable 'v' returned" } |
| 22 |
} |
| 23 |
|
| 24 |
int & |
| 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 & |
| 32 |
f4 () |
| 33 |
{ |
| 34 |
int a[3] = {1, 2, 3}; |
| 35 |
auto& [s, t, u] = a; // { dg-warning "structured bindings only available with" "" { target c++14_down } } |
| 36 |
return s; // { dg-warning "reference to local variable 'a' returned" } |
| 37 |
} |
| 38 |
|
| 39 |
int & |
| 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" } |
| 44 |
} |
| 45 |
|
| 46 |
int & |
| 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" } |
| 52 |
} |
| 53 |
|
| 54 |
int & |
| 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" } |
| 59 |
} |
| 60 |
|
| 61 |
int & |
| 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" } |
| 67 |
} |
| 68 |
|
| 69 |
int * |
| 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 * |
| 77 |
f10 () |
| 78 |
{ |
| 79 |
S v {1, 2}; |
| 80 |
auto& [s, t] = v; // { dg-warning "structured bindings only available with" "" { target c++14_down } } |
| 81 |
return &s; // { dg-warning "address of local variable 'v' returned" } |
| 82 |
} |
| 83 |
|
| 84 |
int * |
| 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 * |
| 92 |
f12 () |
| 93 |
{ |
| 94 |
int a[3] = {1, 2, 3}; |
| 95 |
auto& [s, t, u] = a; // { dg-warning "structured bindings only available with" "" { target c++14_down } } |
| 96 |
return &s; // { dg-warning "address of local variable 'a' returned" } |
| 97 |
} |
| 98 |
|
| 99 |
int * |
| 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" } |
| 104 |
} |
| 105 |
|
| 106 |
int * |
| 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" } |
| 112 |
} |
| 113 |
|
| 114 |
int * |
| 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" } |
| 119 |
} |
| 120 |
|
| 121 |
int * |
| 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" } |
| 127 |
} |
| 128 |
|
| 129 |
int |
| 130 |
main () |
| 131 |
{ |
| 132 |
if (&f1 () != &v.s || &f3 () != &a[0] || f9 () != &v.s || f11 () != &a[0]) |
| 133 |
__builtin_abort (); |
| 134 |
} |