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

            Bug ID: 117727
           Summary: __builtin_bit_cast with target type nullptr_t
                    unimplemented
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tbaeder at redhat dot com
  Target Milestone: ---

See this example code:


typedef __UINTPTR_TYPE__ uintptr_t;
constexpr uintptr_t A = __builtin_bit_cast(uintptr_t, nullptr);
static_assert(A == 0);

typedef decltype(nullptr) nullptr_t;
constexpr decltype(nullptr) N = __builtin_bit_cast(nullptr_t, (uintptr_t)12);
static_assert(N == nullptr);


The first bitcast works, but the second one doesn't:

array.cpp:30:52: sorry, unimplemented: ‘__builtin_bit_cast’ cannot be constant
evaluated because the argument cannot be interpreted
   30 | constexpr decltype(nullptr) N = __builtin_bit_cast(nullptr_t,
(uintptr_t)12);
      |                                                    ^~~~~~~~~

I think this should work similarly. I checked that using std::nullptr_t from
<cstddef> has the same problem.

Reply via email to