C++ Runtime: Signed/unsigned comparison in UnbufferedCharStream.cpp
jm-mikkelsen opened this issue · 0 comments
jm-mikkelsen commented
In UnbufferedCharStream.cpp, there is a comparison between char_traits<char32_t>::eof
and char_traits<wchar_t>::eof
, leading to the following error with Clang 13.
C++ obj-FREEBSD/clang13/release/notpic/antlr4/runtime/Cpp/runtime/src/UnbufferedCharStream.o
antlr4/runtime/Cpp/runtime/src/UnbufferedCharStream.cpp:101:41: error: comparison of integers of different signs: 'std::basic_string<char32_t>::value_type' (aka 'char32_t') and 'std::char_traits<wchar_t>::int_type' (aka 'int') [-Werror,-Wsign-compare]
if (_data[static_cast<size_t>(index)] == std::char_traits<wchar_t>::eof()) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
The type of _data
is std::u32string
, which is defined as having a data type of char32_t
.
The correct comparison should be:
if (_data[static_cast<size_t>(index)] == std::char_traits<char32_t>::eof()) {