foonathan / lexy

C++ parsing DSL
https://lexy.foonathan.net
Boost Software License 1.0
991 stars 66 forks source link

Static assertion failure in benchmarks/swar/main.cpp for MSVC #179

Closed shohirose closed 10 months ago

shohirose commented 10 months ago

MSVC 2022 17.7.5 fails to compile due to the following static assertion failures:

static_assert failed: 'invalid template argument for uniform_int_distribution: N4950 [rand.req.genl]/1.5 requires 
    one of short, int, long, long long, unsigned short, unsigned int, unsigned long, or unsigned long long'
static_assert failed: 'note: char, signed char, unsigned char, char8_t, int8_t, and uint8_t are not allowed'

These are caused by the use of uniformt_int_distribution<char> and uniformt_int_distribution<char32_t> in the benchmarks/swar/main.cpp.

shohirose commented 10 months ago

A quick fix is to use uniform_int_distribution<int> and cast to char or char_32_t:

char random_ascii()
{
    static std::uniform_int_distribution<int> dist(0x00, 0x7F);
    return static_cast<char>(dist(engine));
}

char32_t random_unicode()
{
    static std::uniform_int_distribution<int> dist(0x80, 0x10'FFFF);
    return static_cast<char32_t>(dist(engine));
}

But I am not sure if casting from int to char or char32_t is okay or not.

foonathan commented 10 months ago

Can you make a PR that uses std::uint_least32_t for the random_unicode() case?