GCC already catches these situations so we should handle it too.
GCC warns in C++ mode only (does anybody know why?). I think it is useful in C mode too.
Differential D52835
[Diagnostics] Check integer to floating point number implicit conversions xbolva00 on Oct 3 2018, 10:54 AM. Authored by
Details
GCC already catches these situations so we should handle it too. GCC warns in C++ mode only (does anybody know why?). I think it is useful in C mode too.
Diff Detail Event Timeline
Comment Actions
This comment was removed by xbolva00. Comment Actions Probably should have a test for something like float x = (__uint128_t)-1;, to make sure we print something reasonable.
Comment Actions As noted, this in under LiteralConversion (-Wconversion). GCC has it too under -Wconversion, so I think it is fine as is, or? Comment Actions It's not so much about "which flag group do i need to enable to get the warning"; Comment Actions Ping Anything else to be done here? I would like to finish this patch to work on other things. Comment Actions Since I don't think we have any false positives here, maybe it would be useful to add it to -Wall or -Wextra?
Comment Actions Thanks! I'm sorry for the delayed reviews -- there were wg21 meetings last week, which several of the reviewers were attending. Comment Actions Are you sure check-clang passes with this patch? Comment Actions It looks like you removed a considerable amount of testing coverage; why?
Comment Actions I removed _Float16 related tests since some bots may fail with it, i dont know much about this custom type. System macro - I will fix it.
Comment Actions @aaron.ballman does it make sense to warn for this case only in C/pre-C++11 mode? Since this case in C++11/14/17 is handled by -Wnarrowing, as we see from tests. Or any other solution? Comment Actions I don't think so, because code like this still needs the diagnostic even in C++11 mode, but there's no -Wnarrowing warning for it: float a1 = (1ULL << 31) + 1;
|
Hmm.... I don't terribly understand how this function works. Also, comment above needs to end in a period.
Can you elaborate further as to how this works? Those are 3 pretty suspect looking magic numbers...