public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-1304] c++: Add test for C++23 narrowing conv to bool
@ 2021-06-08 19:35 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2021-06-08 19:35 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:8483dd99268f4d2b68521fcefa78fbdad21f21e8

commit r12-1304-g8483dd99268f4d2b68521fcefa78fbdad21f21e8
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Jun 8 14:24:16 2021 -0400

    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:
---
 gcc/testsuite/g++.dg/cpp23/narrowing-bool1.C | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

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 00000000000..54906c9f99a
--- /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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-06-08 19:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-08 19:35 [gcc r12-1304] c++: Add test for C++23 narrowing conv to bool Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).