Skip to content

Commit e65fb1a

Browse files
[gf] Remove C4018 warnings from GfIntegerCompareLesss
boolean types are considered (unsigned) integral types. Using boolean types with GfNumericCast would implicitly cast to a signed integer in GfIntegerCompareLess, causing Windows to issue C4018 warnings
1 parent 43b8c71 commit e65fb1a

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

pxr/base/gf/numericCast.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,27 @@ GfIntegerCompareLess(T t, U u) noexcept
3131
{
3232
static_assert(std::is_integral_v<T> && std::is_integral_v<U>);
3333

34-
if constexpr (std::is_signed_v<T> == std::is_signed_v<U>) {
34+
if constexpr (std::is_signed_v<T> && std::is_signed_v<U>) {
3535
return t < u;
3636
}
3737
else if constexpr (std::is_signed_v<T>) {
38-
return t < 0 || std::make_unsigned_t<T>(t) < u;
38+
if constexpr (std::is_same_v<U, bool>) {
39+
return t < 0 || std::make_unsigned_t<T>(t) < std::make_unsigned_t<int>(u);
40+
}
41+
else {
42+
return t < 0 || std::make_unsigned_t<T>(t) < u;
43+
}
3944
}
4045
else {
41-
return u >= 0 && t < std::make_unsigned_t<U>(u);
46+
if constexpr (std::is_same_v<T, bool>) {
47+
return u >= 0 && std::make_unsigned_t<int>(t) < std::make_unsigned_t<U>(u);
48+
}
49+
else if constexpr (std::is_same_v<U, bool>) {
50+
return t < std::make_unsigned_t<int>(u);
51+
}
52+
else {
53+
return u >= 0 && t < std::make_unsigned_t<U>(u);
54+
}
4255
}
4356
}
4457

0 commit comments

Comments
 (0)