public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/103511] New: __builtin_bit_cast requires a constructor call
@ 2021-12-01  3:46 de34 at live dot cn
  2021-12-01  8:35 ` [Bug c++/103511] " redi at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: de34 at live dot cn @ 2021-12-01  3:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103511

            Bug ID: 103511
           Summary: __builtin_bit_cast requires a constructor call
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: de34 at live dot cn
  Target Milestone: ---

According to [class.prop] p1, a trivially copyable class may have all of its
constructors deleted. And according to [bit.cast] p1, an object of such a class
type can be created or copied by std::bit_cast since C++20.
But currently gcc's __builtin_bit_cast seemly requires that the target type has
at least one eligible copy or move constructor.

#include <bit>

class Weird {
    Weird(const Weird&) = delete;
    Weird(Weird&&) = delete;
    // works when either constructor is changed to = default
    Weird &operator=(const Weird&) = default;
    Weird &operator=(Weird&&) = default;

    int value_;
};

int main()
{
    auto x [[maybe_unused]] = std::bit_cast<Weird>(0);
}

wandbox links:
https://wandbox.org/permlink/giaPU2R4O2XeF6UF
https://wandbox.org/permlink/lrMmtVw1mt5nZjqY

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-04-14 19:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-01  3:46 [Bug c++/103511] New: __builtin_bit_cast requires a constructor call de34 at live dot cn
2021-12-01  8:35 ` [Bug c++/103511] " redi at gcc dot gnu.org
2021-12-01 11:03 ` jakub at gcc dot gnu.org
2023-07-07 17:19 ` ldionne.2 at gmail dot com
2023-07-07 17:21 ` jakub at gcc dot gnu.org
2023-07-07 21:08 ` ldionne.2 at gmail dot com
2024-04-14 19:22 ` pinskia at gcc dot gnu.org

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).