[Bug c++/96570] Warnings desired for time_t to int coversions

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Aug 12 07:12:48 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96570

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to M Welinder from comment #4)
> > Explicit casts don't, and that's what I was questioning.
> 
> They most certainly do.

I think I understand what you mean now, cases like:

int i = std::max(t, int(time(nullptr)));

?

That's more compelling than:

int now = int(time(nullptr)); // Not good!

There seems absolutely no reason to warn here. The user clearly wants to create
an int *and* has used an explicit cast.

Since you're asking for new checks to detect special cases involving time_t,
why not make it only warn about problem cases? Requiring
int(int64_t(time(nullptr))) here is not acceptable IMHO.


More information about the Gcc-bugs mailing list