Fix mismatched wchar_t sign comparison errors on some platforms

The C++ spec (as of C++17/n4713) does not specify the sign of `wchar_t`,
saying only (in section 6.7.1: Fundamental Types)

> Type wchar_t shall have the same size, signedness, and alignment
> requirements (6.6.5) as one of the other integral types, called its
> underlying type.

On most *nix platforms on AMD64 architecture, `wchar_t` is a signed type
and can be compared with `int32_t` without incident, but on at least
some platforms (tested: clang under FreeBSD 12.1 on AARCH64), `wchar_t`
appears to be unsigned leading to sign comparison warnings:

```
../src/widecharwidth/widechar_width.h:512:48: warning: comparison of
integers of different signs: 'const wchar_t' and 'int32_t' (aka 'int')
[-Wsign-compare]

    return where != std::end(arr) && where->lo <= c;
```

This patch forces the use of wchar_t for the range start/end values in
`widechar_range` and the associated comparison values.
This commit is contained in:
Mahmoud Al-Qudsi 2019-12-18 12:32:04 -06:00
parent d90d4f849c
commit 60670999ad

View File

@ -30,8 +30,8 @@ enum {
/* An inclusive range of characters. */
struct widechar_range {
int32_t lo;
int32_t hi;
wchar_t lo;
wchar_t hi;
};
/* Simple ASCII characters - used a lot, so we check them first. */
@ -506,7 +506,7 @@ static const struct widechar_range widechar_widened_table[] = {
};
template<typename Collection>
bool widechar_in_table(const Collection &arr, int32_t c) {
bool widechar_in_table(const Collection &arr, wchar_t c) {
auto where = std::lower_bound(std::begin(arr), std::end(arr), c,
[](widechar_range p, wchar_t c) { return p.hi < c; });
return where != std::end(arr) && where->lo <= c;