| 1 |
// P1401R5: Narrowing contextual conversions to bool |
| 2 |
// { dg-do compile { target c++11 } } |
| 3 |
|
| 4 |
void f() noexcept(sizeof(char[2])); // { dg-error "narrowing" } conversion of value 2 to type bool |
| 5 |
void g() noexcept(sizeof(char)); // OK, conversion of value 1 to type bool is non-narrowing |
| 6 |
|
| 7 |
#if __cpp_conditional_explicit |
| 8 |
struct S { |
| 9 |
explicit(sizeof(char[2])) S(char); // { dg-error "narrowing" "" { target c++20 } } |
| 10 |
explicit(sizeof(char)) S(bool); // OK, conversion of value 1 to type bool is non-narrowing |
| 11 |
}; |
| 12 |
#endif |
| 13 |
|
| 14 |
static_assert(sizeof(int[2]), ""); // OK, narrowing allowed |
| 15 |
|
| 16 |
#if __cpp_if_constexpr |
| 17 |
int main() |
| 18 |
{ |
| 19 |
if constexpr (sizeof(int[2])) // OK, narrowing allowed |
| 20 |
{} |
| 21 |
} |
| 22 |
#endif |