logoalt Hacker News

lbhdc04/23/20251 replyview on HN

This compiles in clang 21.1.2 with c++26.

    #include <cstdint>
    #include <print>

    constexpr uint8_t f(char ch) {
     return static_cast<uint8_t>(ch);
    }

    int main() {
     constexpr uint8_t r = f('a');
     std::print("{}", r);
    }

Replies

psyclobe04/24/2025

Try consteval , constexpr is a hint. No static casts allowed in constexpr scopes that evaluate as constexpr in c++17 and above (works in c11).

Could be wrong I am no expert…

show 1 reply