From: Jason Merrill Date: Tue, 8 Jun 2021 18:24:16 +0000 (-0400) Subject: c++: Add test for C++23 narrowing conv to bool X-Git-Tag: basepoints/gcc-13~7009 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8483dd99268f4d2b68521fcefa78fbdad21f21e8;p=thirdparty%2Fgcc.git c++: Add test for C++23 narrowing conv to bool From wg21.link/P1401R5. gcc/testsuite/ChangeLog: * g++.dg/cpp23/narrowing-bool1.C: New test. --- diff --git a/gcc/testsuite/g++.dg/cpp23/narrowing-bool1.C b/gcc/testsuite/g++.dg/cpp23/narrowing-bool1.C new file mode 100644 index 000000000000..54906c9f99aa --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp23/narrowing-bool1.C @@ -0,0 +1,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