Skip to content

Commit 7492b55

Browse files
bpo-40686: Fix compiler warnings on _zoneinfo.c (GH-23614) (GH-23804)
"uint8_t day" is unsigned and so "day < 0" test is always true. Remove the test to fix the following warnings on Windows: modules\_zoneinfo.c(1224): warning C4068: unknown pragma modules\_zoneinfo.c(1225): warning C4068: unknown pragma modules\_zoneinfo.c(1227): warning C4068: unknown pragma (cherry picked from commit aefb69b) Co-authored-by: Victor Stinner <[email protected]> Co-authored-by: Victor Stinner <[email protected]>
1 parent cd7412e commit 7492b55

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

Modules/_zoneinfo.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ static void
171171
update_strong_cache(const PyTypeObject *const type, PyObject *key,
172172
PyObject *zone);
173173
static PyObject *
174-
zone_from_strong_cache(const PyTypeObject *const type, PyObject *key);
174+
zone_from_strong_cache(const PyTypeObject *const type, PyObject *const key);
175175

176176
static PyObject *
177177
zoneinfo_new_instance(PyTypeObject *type, PyObject *key)
@@ -1219,15 +1219,9 @@ calendarrule_new(uint8_t month, uint8_t week, uint8_t day, int8_t hour,
12191219
return -1;
12201220
}
12211221

1222-
// day is an unsigned integer, so day < 0 should always return false, but
1223-
// if day's type changes to a signed integer *without* changing this value,
1224-
// it may create a bug. Considering that the compiler should be able to
1225-
// optimize out the first comparison if day is an unsigned integer anyway,
1226-
// we will leave this comparison in place and disable the compiler warning.
1227-
#pragma GCC diagnostic push
1228-
#pragma GCC diagnostic ignored "-Wtype-limits"
1229-
if (day < 0 || day > 6) {
1230-
#pragma GCC diagnostic pop
1222+
// If the 'day' parameter type is changed to a signed type,
1223+
// "day < 0" check must be added.
1224+
if (/* day < 0 || */ day > 6) {
12311225
PyErr_Format(PyExc_ValueError, "Day must be in [0, 6]");
12321226
return -1;
12331227
}

0 commit comments

Comments
 (0)