-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Open
Labels
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"constevalC++20 constevalC++20 consteval
Description
The following code should succeed, but fails to compile:
#include <bit>
// error: constexpr variable 'x' must be initialized by a constant expression
constexpr auto x = std::bit_cast<int>("xyz");
error: constexpr variable 'x' must be initialized by a constant expression
constexpr auto x = std::bit_cast<int>("xyz");
^ ~~~~~~~~~~~~~~~~~~~~~~~~~
note: subexpression not valid in a constant expression
return __builtin_bit_cast(_To, __from);
^
note: in call to 'bit_cast("xyz")'
constexpr auto x = std::bit_cast<int>("xyz");
^
1 error generated.
Putting the string literal into a char[4]
first solves the problem, but it should work either way.
frederick-vs-ja
Metadata
Metadata
Assignees
Labels
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"constevalC++20 constevalC++20 consteval
Type
Projects
Status
No status