Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

constexpr __builtin_bit_cast involving bit-field #54018

Open
fsb4000 opened this issue Feb 23, 2022 · 7 comments
Open

constexpr __builtin_bit_cast involving bit-field #54018

fsb4000 opened this issue Feb 23, 2022 · 7 comments
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@fsb4000
Copy link
Member

fsb4000 commented Feb 23, 2022

#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

@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed new issue labels Feb 23, 2022
@llvmbot
Copy link
Collaborator

llvmbot commented Feb 23, 2022

@llvm/issue-subscribers-clang-frontend

@0-wiz-0
Copy link

0-wiz-0 commented Jul 4, 2022

I see this error message when I try to build libcxxabi 14.0.6 on NetBSD 9.99.98/amd64 (which comes with gcc 10.3.0 in case it matters):

[ 23%] Building CXX object src/CMakeFiles/cxxabi_static.dir/cxa_virtual.cpp.o                      
In file included from /scratch/lang/libcxxabi/work/libcxx-14.0.6.src/include/__compare/strong_order.h:12,                                                                                              
                 from /scratch/lang/libcxxabi/work/libcxx-14.0.6.src/include/__compare/weak_order.h:14,
                 from /scratch/lang/libcxxabi/work/libcxx-14.0.6.src/include/__compare/partial_order.h:14,
                 from /scratch/lang/libcxxabi/work/libcxx-14.0.6.src/include/__compare/compare_partial_order_fallback.h:13,
                 from /scratch/lang/libcxxabi/work/libcxx-14.0.6.src/include/compare:144,                                                                                                              
                 from /scratch/lang/libcxxabi/work/libcxx-14.0.6.src/include/utility:236,                                                                                                              
                 from /scratch/lang/libcxxabi/work/libcxx-14.0.6.src/include/__functional_base:26,
                 from /scratch/lang/libcxxabi/work/libcxx-14.0.6.src/include/memory:808,
                 from /scratch/lang/libcxxabi/work/libcxxabi-14.0.6.src/../libcxx/src/include/atomic_support.h:13,
                 from /scratch/lang/libcxxabi/work/libcxxabi-14.0.6.src/src/cxa_default_handlers.cpp:19:
/scratch/lang/libcxxabi/work/libcxx-14.0.6.src/include/__bit/bit_cast.h: In function 'constexpr _ToType std::__1::bit_cast(const _FromType&)':
/scratch/lang/libcxxabi/work/libcxx-14.0.6.src/include/__bit/bit_cast.h:31:38: error: expected primary-expression before ',' token
   31 |     return __builtin_bit_cast(_ToType, __from);                                            
      |                                      ^                                                     

@0323pin
Copy link

0323pin commented Jul 5, 2022

Hi,

Sorry for jumping in uninvited but, would this just compile with gcc >= 11?

@fsb4000
Copy link
Member Author

fsb4000 commented Jul 6, 2022

Hi @0323pin !

My code sample works for gcc 11 and MSVC 2022: https://godbolt.org/z/s1ETKj5ET

@0323pin
Copy link

0323pin commented Jul 6, 2022

@fsb4000 Thanks!

@tbaederr
Copy link
Contributor

@JohelEGP
Copy link

Unfortunately, the presence of the error message and the test don't imply that this is being actively worked on. Just that it was known at the time it was implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

7 participants