public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "de34 at live dot cn" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/101906] New: Constant evaluation failure in concepts Date: Sat, 14 Aug 2021 05:47:39 +0000 [thread overview] Message-ID: <bug-101906-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101906 Bug ID: 101906 Summary: Constant evaluation failure in concepts Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: de34 at live dot cn Target Milestone: --- Following code fails to compile when the macro MAYBE_CWG1581 is not defined. #include <bit> #include <cstddef> namespace test { template<int> using voidify = void; template<std::size_t N> struct obj_rep { unsigned char value[N]; }; template<class T> concept constant_value_initializable = requires { typename voidify<(std::bit_cast<obj_rep<sizeof(T)>>(T()), 0)>; }; } struct foo { int x; }; struct bar { int x = -1; }; #ifdef MAYBE_CWG1581 using my_void = test::voidify<(std::bit_cast<test::obj_rep<sizeof(bar)>>(bar()), 0)>; #endif static_assert(test::constant_value_initializable<int>); static_assert(test::constant_value_initializable<foo>); static_assert(test::constant_value_initializable<bar>); // It's buggy static_assert(!test::constant_value_initializable<int*>); // Correct: std::bit_cast doesn't perform constant evaluation when involving pointers int main() { } The godbolt link: https://gcc.godbolt.org/z/6dscsaGTM It seems that currently gcc fails to generate the definition of std::bit_cast<SomeType> when determining if the concept is satisfied, while it can generate such definition when a type alias declaration is encountered. Maybe related to WG21 P0859R0/CWG1581.
next reply other threads:[~2021-08-14 5:47 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-08-14 5:47 de34 at live dot cn [this message] 2021-11-03 19:37 ` [Bug c++/101906] " ppalka at gcc dot gnu.org 2022-03-24 15:13 ` ppalka at gcc dot gnu.org 2022-09-12 21:06 ` cvs-commit at gcc dot gnu.org 2022-09-12 21:07 ` ppalka at gcc dot gnu.org
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=bug-101906-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@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).