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