public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-1304] c++: Add test for C++23 narrowing conv to bool Date: Tue, 8 Jun 2021 19:35:04 +0000 (GMT) [thread overview] Message-ID: <20210608193504.1178B3984C23@sourceware.org> (raw) 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
reply other threads:[~2021-06-08 19:35 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210608193504.1178B3984C23@sourceware.org \ --to=jason@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).