mirror of
https://github.com/python/cpython.git
synced 2025-09-30 12:21:51 +00:00
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 aefb69b23f
)
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
parent
cd7412e3c4
commit
7492b55ea0
1 changed files with 4 additions and 10 deletions
|
@ -171,7 +171,7 @@ static void
|
||||||
update_strong_cache(const PyTypeObject *const type, PyObject *key,
|
update_strong_cache(const PyTypeObject *const type, PyObject *key,
|
||||||
PyObject *zone);
|
PyObject *zone);
|
||||||
static PyObject *
|
static PyObject *
|
||||||
zone_from_strong_cache(const PyTypeObject *const type, PyObject *key);
|
zone_from_strong_cache(const PyTypeObject *const type, PyObject *const key);
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
zoneinfo_new_instance(PyTypeObject *type, PyObject *key)
|
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,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// day is an unsigned integer, so day < 0 should always return false, but
|
// If the 'day' parameter type is changed to a signed type,
|
||||||
// if day's type changes to a signed integer *without* changing this value,
|
// "day < 0" check must be added.
|
||||||
// it may create a bug. Considering that the compiler should be able to
|
if (/* day < 0 || */ day > 6) {
|
||||||
// optimize out the first comparison if day is an unsigned integer anyway,
|
|
||||||
// we will leave this comparison in place and disable the compiler warning.
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignored "-Wtype-limits"
|
|
||||||
if (day < 0 || day > 6) {
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
PyErr_Format(PyExc_ValueError, "Day must be in [0, 6]");
|
PyErr_Format(PyExc_ValueError, "Day must be in [0, 6]");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue