Summary
test/unittest/type_traits_test.cpp contains a static_assert that assumes char is signed. This fails to compile on platforms where char is unsigned by default, such as aarch64-linux, ppc64, and several embedded targets.
Affected line
https://github.com/atcoder/ac-library/blob/v1.6/test/unittest/type_traits_test.cpp#L47
static_assert(is_same<unsigned char, internal::to_unsigned_t<char>>::value, "");
This holds when char is signed (e.g. x86_64-linux), because to_unsigned_t<char> resolves to unsigned char. On platforms where char is unsigned, internal::is_signed_int<char> is false, so to_unsigned_t<char> resolves to char itself — not unsigned char — and the assertion fails.
Reproduction
Build the unit tests on any platform where char is unsigned, or force it on x86_64:
g++ -funsigned-char -std=c++14 -I. test/unittest/type_traits_test.cpp -c
Output:
type_traits_test.cpp:47:70: error: static assertion failed
47 | static_assert(is_same<unsigned char, internal::to_unsigned_t<char>>::value, "");
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
Suggested fix
Guard the assertion with CHAR_MIN < 0 so the correct relationship is checked on each platform:
#if CHAR_MIN < 0
static_assert(is_same<unsigned char, internal::to_unsigned_t<char>>::value, "");
#else
static_assert(is_same<char, internal::to_unsigned_t<char>>::value, "");
#endif
(<climits> needs to be included.)
The library itself works correctly on these platforms — only this one test assertion is incorrect. PR coming.
Environment
- Compiler: GCC 15.2.0
- Platform:
aarch64-linux
- Standard: C++14 / C++17 (both reproduce)
Summary
test/unittest/type_traits_test.cppcontains astatic_assertthat assumescharis signed. This fails to compile on platforms wherecharis unsigned by default, such asaarch64-linux,ppc64, and several embedded targets.Affected line
https://github.com/atcoder/ac-library/blob/v1.6/test/unittest/type_traits_test.cpp#L47
This holds when
charis signed (e.g.x86_64-linux), becauseto_unsigned_t<char>resolves tounsigned char. On platforms wherecharis unsigned,internal::is_signed_int<char>isfalse, soto_unsigned_t<char>resolves tocharitself — notunsigned char— and the assertion fails.Reproduction
Build the unit tests on any platform where
charis unsigned, or force it onx86_64:Output:
Suggested fix
Guard the assertion with
CHAR_MIN < 0so the correct relationship is checked on each platform:(
<climits>needs to be included.)The library itself works correctly on these platforms — only this one test assertion is incorrect. PR coming.
Environment
aarch64-linux