Skip to content

Commit ed199c8

Browse files
authored
[libc] Workaround for gcc complaining about implicit conversions with the ternary ?: operator. (#124820)
Fixes #120427, #122745 This is caused by a -Wconversion false-positive bug in gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101537
1 parent 6338bde commit ed199c8

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

libc/src/__support/FPUtil/except_value_utils.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,19 @@ template <typename T, size_t N> struct ExceptValues {
8181
StorageType out_bits = values[i].rnd_towardzero_result;
8282
switch (fputil::quick_get_round()) {
8383
case FE_UPWARD:
84-
out_bits += sign ? values[i].rnd_downward_offset
85-
: values[i].rnd_upward_offset;
84+
if (sign)
85+
out_bits += values[i].rnd_downward_offset;
86+
else
87+
out_bits += values[i].rnd_upward_offset;
8688
break;
8789
case FE_DOWNWARD:
88-
out_bits += sign ? values[i].rnd_upward_offset
89-
: values[i].rnd_downward_offset;
90+
// Use conditionals instead of ternary operator to work around gcc's
91+
// -Wconversion false positive bug:
92+
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101537
93+
if (sign)
94+
out_bits += values[i].rnd_upward_offset;
95+
else
96+
out_bits += values[i].rnd_downward_offset;
9097
break;
9198
case FE_TONEAREST:
9299
out_bits += values[i].rnd_tonearest_offset;

0 commit comments

Comments
 (0)