Issue 117166
Summary __builtin_bit_cast does not allow bitcasting from nullptr_t
Labels clang:frontend, constexpr
Assignees
Reporter tbaederr
    `nullptr_t` is not a pointer type, see the `static_assert` in https://godbolt.org/z/vjq1Tse7W


In this example, the second bitcast works, but the first one does not:
```c++
typedef __UINTPTR_TYPE__ uintptr_t;
constexpr uintptr_t A = __builtin_bit_cast(uintptr_t, nullptr);


typedef decltype(nullptr) nullptr_t;
constexpr decltype(nullptr) N = __builtin_bit_cast(nullptr_t, (uintptr_t)12);
static_assert(N == nullptr);
```
The output suggests some bogus reason though:

```console
./array.cpp:26:21: error: constexpr variable 'A' must be initialized by a constant _expression_
   26 | constexpr uintptr_t A = __builtin_bit_cast(uintptr_t, nullptr);
      | ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./array.cpp:26:25: note: indeterminate value can only initialize an object of type 'unsigned char' or 'std::byte'; 'unsigned long' is invalid
   26 | constexpr uintptr_t A = __builtin_bit_cast(uintptr_t, nullptr);
      | ^
```

GCC accepts the first one, but not the second. I opened https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117727 for that.

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to