-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Closed as not planned
Labels
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"constexprAnything related to constant evaluationAnything related to constant evaluationinvalidResolved as invalid, i.e. not a bugResolved as invalid, i.e. not a bug
Description
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:
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:
./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.
Metadata
Metadata
Assignees
Labels
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"constexprAnything related to constant evaluationAnything related to constant evaluationinvalidResolved as invalid, i.e. not a bugResolved as invalid, i.e. not a bug