https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96570
Bug ID: 96570
Summary: Warnings desired for time_t to int coversions
Product: gcc
Version: 10.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: terra at gnome dot org
Target Milestone: ---
This is a wishlist item. It's filed for C++ but would apply to C too.
It would be useful to have some mechanism to cause warnings to be emitted at
compile-time when values of type time_t are cut down in size. For example:
int now = time(nullptr); // Not good!
int now = int(time(nullptr)); // Not good!
// (This one occurs not only when someone wanted the compiler to shut up,
// but also occurs when using casts to resolve overload resolution.)
void foo(int);
...
time_t now = time(nullptr);
foo(now); // Not good
Note: this is desired for explicit casts too. Hence -Wconversion in its
current form is not what I am looking for. I am not sure how, if at all, the
warnings should be suppressed, but a cast via a 64-bit type,
int(int64_t(time(null))), is an option.