Commit dcc31061 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Avoid unary negation of unsigned in FormatValue

Summary:
[Folly] Avoid unary negation of unsigned in `FormatValue`, which some compilers may warn against.

```
folly\format-inl.h(452): error C4146: unary minus operator applied to unsigned type, result still unsigned
```

Reviewed By: Orvid

Differential Revision: D14141989

fbshipit-source-id: 3bff06fe09fd4ec22d93b72a74f086ad9c576692
parent 9715d540
......@@ -449,7 +449,9 @@ class FormatValue<
char sign;
if (std::is_signed<T>::value) {
if (folly::is_negative(val_)) {
uval = UT(-static_cast<UT>(val_));
// avoid unary negation of unsigned types, which may be warned against
// avoid ub signed integer overflow, which ubsan checks against
uval = UT(0 - static_cast<UT>(val_));
sign = '-';
} else {
uval = static_cast<UT>(val_);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment