| 1 |
// PR c++/110358 |
| 2 |
// { dg-do compile { target c++20 } } |
| 3 |
// { dg-options "-Wdangling-reference" } |
| 4 |
|
| 5 |
template<bool B> |
| 6 |
struct bool_constant { |
| 7 |
static constexpr bool value = B; |
| 8 |
constexpr operator bool() const { return value; } |
| 9 |
}; |
| 10 |
|
| 11 |
using true_type = bool_constant<true>; |
| 12 |
using false_type = bool_constant<false>; |
| 13 |
|
| 14 |
struct S { |
| 15 |
int i; |
| 16 |
template<bool B> |
| 17 |
[[gnu::no_dangling(B)]] int &foo (const int &); |
| 18 |
}; |
| 19 |
|
| 20 |
void |
| 21 |
g () |
| 22 |
{ |
| 23 |
[[maybe_unused]] const int &x0 = S().foo<false_type{}> (42); // { dg-warning "dangling" } |
| 24 |
[[maybe_unused]] const int &x1 = S().foo<true_type{}> (42); // { dg-bogus "dangling" } |
| 25 |
} |
| 26 |
|