Skip to content

Commit d0151aa

Browse files
mkruskal-googlecopybara-github
authored andcommitted
Fix const INFINITY issue on MSVC.
We previously hit this for NAN, but it appears the latest version of MSVC used in windows github runners has the same issue for INFINITY. The same strategy can be applied here. This will be backported to fix broken release branches. PiperOrigin-RevId: 700042372
1 parent da8bcc8 commit d0151aa

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

upb/message/internal/message.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
// Must be last.
1818
#include "upb/port/def.inc"
1919

20-
const float kUpb_FltInfinity = INFINITY;
21-
const double kUpb_Infinity = INFINITY;
22-
2320
// The latest win32 SDKs have an invalid definition of NAN.
2421
// https://developercommunity.visualstudio.com/t/NAN-is-no-longer-compile-time-constant-i/10688907
2522
//
@@ -30,15 +27,24 @@ const double kUpb_Infinity = INFINITY;
3027
#if __has_builtin(__builtin_nan)
3128
#define UPB_NAN __builtin_nan("0")
3229
#endif
30+
#if __has_builtin(__builtin_inf)
31+
#define UPB_INFINITY __builtin_inf()
32+
#endif
3333
#endif
3434
#ifndef UPB_NAN
3535
#define UPB_NAN 0.0 / 0.0
3636
#endif
37+
#ifndef UPB_INFINITY
38+
#define UPB_INFINITY 1.0 / 0.0
39+
#endif
3740
#else
3841
// For !_WIN32, assume math.h works.
3942
#define UPB_NAN NAN
43+
#define UPB_INFINITY INFINITY
4044
#endif
4145

46+
const float kUpb_FltInfinity = UPB_INFINITY;
47+
const double kUpb_Infinity = UPB_INFINITY;
4248
const double kUpb_NaN = UPB_NAN;
4349

4450
bool UPB_PRIVATE(_upb_Message_EnsureAvailable)(struct upb_Message* msg,

0 commit comments

Comments
 (0)