[PATCH] D52835: [Diagnostics] Check integer to floating point number implicit conversions

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 6 07:59:12 PST 2019


aaron.ballman added a comment.

In D52835#1412416 <https://reviews.llvm.org/D52835#1412416>, @xbolva00 wrote:

> @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.


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;`



================
Comment at: test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp:136
   Agg<float> f8 = {EnumVal};  // OK
+  // expected-warning at +1 {{implicit conversion from 'int' to 'float' changes value from 123456789 to 1.2345679E+8}}
   Agg<float> f9 = {123456789};  // expected-error {{ cannot be narrowed }} expected-note {{silence}}
----------------
xbolva00 wrote:
> aaron.ballman wrote:
> > I don't think we want the warning triggered in either of these cases -- they already have an error diagnostic on the same line for the same issue.
> Any recommended way how it should be handled?
Why is it triggering twice in the first place? Template instantiation, maybe?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D52835/new/

https://reviews.llvm.org/D52835





More information about the cfe-commits mailing list