Skip to content

constexpr __builtin_bit_cast involving bit-field #54018

@fsb4000

Description

@fsb4000
#include <bit>
#include <type_traits>

template <typename Derived, typename Type>
struct alignas(sizeof(Type)) bit_field
{
};

struct S : bit_field<S, int>
{
    bool a : 1;
 
    constexpr S() noexcept = default;
    constexpr S(int i) noexcept: S( std::bit_cast<S>( i ) ) {}
};

static_assert(sizeof(S) == sizeof(int));
static_assert(std::is_trivially_copyable_v<S>);
static_assert(std::is_trivially_copyable_v<int>);

constexpr S sa = 0x00000001; // <source>(21)

https://godbolt.org/z/z99v39n1Y

bit_cast.h:31:12: note: constexpr bit_cast involving bit-field is not yet supported
    return __builtin_bit_cast(_ToType, __from);
           ^

Well, because of the note, I think this is a known issue.

But I couldn't find it via github issues, so I decided to create a new one.

https://github.com/llvm/llvm-project/issues?q=__builtin_bit_cast+is%3Aopen

https://github.com/llvm/llvm-project/issues?q=bit_cast+is%3Aopen

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions