| 1 |
// RUN: %clang_cc1 -std=c++26 -fsyntax-only -verify %s |
| 2 |
|
| 3 |
auto&& f1() { |
| 4 |
return 42; // expected-error{{returning reference to local temporary object}} |
| 5 |
} |
| 6 |
const double& f2() { |
| 7 |
static int x = 42; |
| 8 |
return x; // expected-error{{returning reference to local temporary object}} |
| 9 |
} |
| 10 |
auto&& id(auto&& r) { |
| 11 |
return static_cast<decltype(r)&&>(r); |
| 12 |
} |
| 13 |
auto&& f3() { |
| 14 |
return id(42); // OK, but probably a bug |
| 15 |
} |
| 16 |
|
| 17 |
void unevaluated() { |
| 18 |
using a = decltype ([] () -> const int & { |
| 19 |
const int &i = 0; // expected-note {{binding reference variable 'i' here}} |
| 20 |
return i; // expected-error{{returning reference to local temporary object}} |
| 21 |
} ()); |
| 22 |
} |
| 23 |
|
| 24 |
static_assert(__is_convertible(int, const int &)); |
| 25 |
static_assert(__is_nothrow_convertible(int, const int &)); |