Skip to content

Commit aefb69b

Browse files
authored
bpo-40686: Fix compiler warnings on _zoneinfo.c (GH-23614)
"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
1 parent 37caeb1 commit aefb69b

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
@@ -172,7 +172,7 @@ static void
172172
update_strong_cache(const PyTypeObject *const type, PyObject *key,
173173
PyObject *zone);
174174
static PyObject *
175-
zone_from_strong_cache(const PyTypeObject *const type, PyObject *key);
175+
zone_from_strong_cache(const PyTypeObject *const type, PyObject *const key);
176176

177177
static PyObject *
178178
zoneinfo_new_instance(PyTypeObject *type, PyObject *key)
@@ -1214,15 +1214,9 @@ calendarrule_new(uint8_t month, uint8_t week, uint8_t day, int8_t hour,
12141214
return -1;
12151215
}
12161216

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

0 commit comments

Comments
 (0)