| 1 |
// PR c++/110358 |
| 2 |
// { dg-do compile { target c++20 } } |
| 3 |
// { dg-options "-Wdangling-reference" } |
| 4 |
|
| 5 |
template<class T> constexpr bool is_reference_v = false; |
| 6 |
template<class T> constexpr bool is_reference_v<T&> = true; |
| 7 |
template<class T> constexpr bool is_reference_v<T&&> = true; |
| 8 |
|
| 9 |
template <typename T> |
| 10 |
struct [[gnu::no_dangling(is_reference_v<T>)]] S { |
| 11 |
int i; |
| 12 |
int &foo (const int &); |
| 13 |
}; |
| 14 |
|
| 15 |
template <typename T1, typename T2> |
| 16 |
struct X { |
| 17 |
template <typename U1 = T1, typename U2 = T2> |
| 18 |
struct [[gnu::no_dangling(is_reference_v<U1> && is_reference_v<U2>)]] Y { |
| 19 |
int i; |
| 20 |
int &foo (const int &); |
| 21 |
}; |
| 22 |
}; |
| 23 |
|
| 24 |
void |
| 25 |
g () |
| 26 |
{ |
| 27 |
[[maybe_unused]] const int &x0 = S<int&>().foo (42); // { dg-bogus "dangling" } |
| 28 |
[[maybe_unused]] const int &x1 = S<int>().foo (42); // { dg-warning "dangling" } |
| 29 |
[[maybe_unused]] const auto &x2 = X<int, int&>::Y<>().foo (42); // { dg-warning "dangling" } |
| 30 |
[[maybe_unused]] const auto &x3 = X<int&, int&>::Y<>().foo (42); // { dg-bogus "dangling" } |
| 31 |
} |
| 32 |
|