https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85861
--- Comment #15 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Jonny Grant from comment #13) > (In reply to Jonathan Wakely from comment #11) > > My guess is that we don't want to warn about conversions that are > > well-defined and the original value can be obtained by a round-trip. > > Converting a size_t to an int is lossy, i.e. converting back to size_t may > > not give the original value. But converting an int to size_t and back to an > > int is value preserving. > > Do you mean because size_t is 64bit typically, and int is only 32bit? > > I tested this on my 64bit Ubuntu > It converts a size_t 9,223,372,036,854,775,807 to an int Which gives -1. > and ends up with 18,446,744,073,709,551,615 Because that's what (size_t)-1 equals. > > Which I was surprised about, as I thought int was 4 bytes. It is. > I had expected > 4,294,967,295 You converted to size_t, not unsigned int. See https://en.wikipedia.org/wiki/Sign_extension