public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "janpmoeller at gmx dot de" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/108934] New: bit_cast'ing to long double errors out with "the argument cannot be interpreted" since gcc-12 Date: Sat, 25 Feb 2023 22:58:31 +0000 [thread overview] Message-ID: <bug-108934-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108934 Bug ID: 108934 Summary: bit_cast'ing to long double errors out with "the argument cannot be interpreted" since gcc-12 Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: janpmoeller at gmx dot de Target Milestone: --- In gcc-trunk, gcc-12.2 and gcc-12.1, the following code fails to compile, while gcc-11.3 accepts it: ///////////////////////////////////////////////////////////////////////////////////////////////////////////// #include <array> #include <bit> #include <cstdint> using uint64_x_2_t = std::array<std::uint64_t, 2>; using uint32_x_2_t = std::array<std::uint32_t, 2>; using uint16_x_2_t = std::array<std::uint16_t, 2>; static_assert(sizeof(long double) == sizeof(uint64_x_2_t)); static_assert(sizeof(double) == sizeof(uint32_x_2_t)); static_assert(sizeof(float) == sizeof(uint16_x_2_t)); constexpr long double testld = 42.42; constexpr double testd = 42.42; constexpr float testf = 42.42f; constexpr uint64_x_2_t test_uint64_x_2_t{1u, 2u}; constexpr uint32_x_2_t test_uint32_x_2_t{1u, 2u}; constexpr uint16_x_2_t test_uint16_x_2_t{1u, 2u}; constexpr auto ld_to_uint64_x_2_t = std::bit_cast<uint64_x_2_t>(testld); // works! (reverse direction) constexpr auto d_to_uint32_x_2_t = std::bit_cast<uint32_x_2_t>(testd); constexpr auto f_to_uint16_x_2_t = std::bit_cast<uint16_x_2_t>(testf); constexpr auto default_uint64_x_2_t_to_ld = std::bit_cast<long double>(uint64_x_2_t{}); // works! (default initialized) constexpr auto default_uint32_x_2_t_to_d = std::bit_cast<double>(uint32_x_2_t{}); constexpr auto default_uint16_x_2_t_to_f = std::bit_cast<float>(uint16_x_2_t{}); constexpr auto temp_uint64_x_2_t_to_ld = std::bit_cast<long double>(uint64_x_2_t{1u, 2u}); // <= fails constexpr auto temp_uint32_x_2_t_to_d = std::bit_cast<double>(uint32_x_2_t{1u, 2u}); constexpr auto temp_uint16_x_2_t_to_f = std::bit_cast<float>(uint16_x_2_t{1u, 2u}); constexpr auto uint64_x_2_t_to_ld = std::bit_cast<long double>(test_uint64_x_2_t); // <= fails constexpr auto uint32_x_2_t_to_d = std::bit_cast<double>(test_uint32_x_2_t); constexpr auto uint16_x_2_t_to_f = std::bit_cast<float>(test_uint16_x_2_t); ///////////////////////////////////////////////////////////////////////////////////////////////////////////// The compile error for both offending lines is: /usr/include/c++/12/bit:87:33: sorry, unimplemented: ‘__builtin_bit_cast’ cannot be constant evaluated because the argument cannot be interpreted The strange thing is that this error only seems to appear if the array is aggregate-initialized; default initialized arrays do not trigger the error. float and double do not trigger the error either. Replacing std::array with a struct aggregate type behaves the same as the array example above. The reverse direction, i.e. bit_cast'ing from long double to array, seems to be working fine. The above example on compiler explorer: https://godbolt.org/z/ba5d6hEG1
next reply other threads:[~2023-02-25 22:58 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-02-25 22:58 janpmoeller at gmx dot de [this message] 2023-02-25 23:09 ` [Bug c++/108934] " pinskia at gcc dot gnu.org 2023-02-25 23:09 ` pinskia at gcc dot gnu.org 2023-02-25 23:11 ` pinskia at gcc dot gnu.org 2023-02-25 23:15 ` pinskia at gcc dot gnu.org 2023-03-01 15:56 ` jakub at gcc dot gnu.org 2023-03-01 15:57 ` [Bug c++/108934] [12/13 Regression] " jakub at gcc dot gnu.org 2023-03-01 16:02 ` jakub at gcc dot gnu.org 2023-03-01 16:19 ` jakub at gcc dot gnu.org 2023-03-02 8:28 ` cvs-commit at gcc dot gnu.org 2023-03-02 8:29 ` [Bug c++/108934] [12 " jakub at gcc dot gnu.org 2023-03-19 5:30 ` cvs-commit at gcc dot gnu.org 2023-03-20 10:28 ` jakub 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-108934-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).