aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp23/narrowing-bool1.C
blob: 54906c9f99aa3a6aaeebc9878f7ed2b6dfbe6e81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// P1401R5: Narrowing contextual conversions to bool
// { dg-do compile { target c++11 } }

void f() noexcept(sizeof(char[2])); // { dg-error "narrowing" } conversion of value 2 to type bool
void g() noexcept(sizeof(char)); // OK, conversion of value 1 to type bool is non-narrowing

#if __cpp_conditional_explicit
struct S {
  explicit(sizeof(char[2])) S(char); // { dg-error "narrowing" "" { target c++20 } }
  explicit(sizeof(char)) S(bool); // OK, conversion of value 1 to type bool is non-narrowing
};
#endif

static_assert(sizeof(int[2]), ""); // OK, narrowing allowed

#if __cpp_if_constexpr
int main()
{
  if constexpr (sizeof(int[2])) // OK, narrowing allowed
    {}
}
#endif