Skip to content

Commit 8310fdb

Browse files
sunyabpixar-oss
authored andcommitted
gf: Temporarily suppress warning C4018 in GfIntegerCompareLess
This code reportedly began emitting this warning in OpenUSD 25.11. For now, we simply silence this warning rather than make any low-level changes this late in the release cycle. We expect to remove this in the subsequent release. This change also adds the unit test cases for bool conversions in GfNumericCast from pull request #3855. See #3855 (Internal change: 2382628)
1 parent 607f315 commit 8310fdb

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

pxr/base/gf/numericCast.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "pxr/pxr.h"
1111

1212
#include "pxr/base/gf/traits.h"
13+
#include "pxr/base/arch/pragmas.h"
1314

1415
#include <cmath>
1516
#include <limits>
@@ -29,6 +30,15 @@ template <class T, class U>
2930
constexpr bool
3031
GfIntegerCompareLess(T t, U u) noexcept
3132
{
33+
// XXX:
34+
// On Visual Studio warning C4018 (signed/unsigned mismatch) is emitted
35+
// when this function is used with boolean values. Just disable this
36+
// for now.
37+
#if defined(ARCH_COMPILER_MSVC)
38+
ARCH_PRAGMA_PUSH
39+
ARCH_PRAGMA(warning(disable:4018))
40+
#endif
41+
3242
static_assert(std::is_integral_v<T> && std::is_integral_v<U>);
3343

3444
if constexpr (std::is_signed_v<T> == std::is_signed_v<U>) {
@@ -40,6 +50,10 @@ GfIntegerCompareLess(T t, U u) noexcept
4050
else {
4151
return u >= 0 && t < std::make_unsigned_t<U>(u);
4252
}
53+
54+
#if defined(ARCH_COMPILER_MSVC)
55+
ARCH_PRAGMA_POP
56+
#endif
4357
}
4458

4559
enum GfNumericCastFailureType {

pxr/base/gf/testenv/testGfHardToReach.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,33 @@ main(int argc, char *argv[])
252252
static_cast<float>(
253253
std::numeric_limits<int16_t>::lowest()) - 1.0f,
254254
&failType) && failType == GfNumericCastNegOverflow);
255+
256+
// bool -> int
257+
TF_AXIOM(GfNumericCast<int>(true).value() == 1);
258+
TF_AXIOM(GfNumericCast<int>(false).value() == 0);
259+
260+
// int -> bool
261+
TF_AXIOM(GfNumericCast<bool>(0).value() == false);
262+
TF_AXIOM(GfNumericCast<bool>(1).value() == true);
263+
264+
TF_AXIOM(!GfNumericCast<bool>(-1, &failType) &&
265+
failType == GfNumericCastNegOverflow);
266+
267+
TF_AXIOM(!GfNumericCast<bool>(2, &failType) &&
268+
failType == GfNumericCastPosOverflow);
269+
270+
TF_AXIOM(GfNumericCast<bool>(
271+
static_cast<unsigned>(0)).value() == false);
272+
TF_AXIOM(GfNumericCast<bool>(
273+
static_cast<unsigned>(1)).value() == true);
274+
275+
TF_AXIOM(!GfNumericCast<bool>(
276+
static_cast<unsigned>(2), &failType) &&
277+
failType == GfNumericCastPosOverflow);
278+
279+
TF_AXIOM(!GfNumericCast<bool>(
280+
std::numeric_limits<unsigned>::max(), &failType) &&
281+
failType == GfNumericCastPosOverflow);
255282

256283
// unsigned
257284
TF_AXIOM(GfNumericCast<uint16_t>(

0 commit comments

Comments
 (0)