[PATCH] D64666: [Sema] Enable -Wimplicit-float-conversion for integral to floating point precision loss

Ziang Wan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 30 11:16:36 PDT 2019

ziangwan marked an inline comment as done.
ziangwan added inline comments.

Comment at: clang/lib/Sema/SemaChecking.cpp:11656
+  IsListInit =
+      IsListInit || (isa<InitListExpr>(OrigE) && S.getLangOpts().CPlusPlus);
aaron.ballman wrote:
> ziangwan wrote:
> > aaron.ballman wrote:
> > > Do you want to perform the `isa<>` on `OrigE` or on `E` which has had paren and implicit casts stripped?
> > When we are dealing with Initialization list syntax expression, the out-most expression will be of type `InitListExpr`. Since the out-most expression is not `ImplicitCastExpr`, `IgnoreParenImpCasts()` has no effect on the `OrigE` object. In other words, `OrigE` and `E` will be the same when `isa<InitListExpr>(OrigE)` evaluates to true.
> > 
> > In this case, I personally prefer `OrigE` since it is the "non-processed" object. However, the rest of the function uses `E` only. I can change it to `E`.
> Ah, I was thinking we had to contend with a case like `({1, 2, 3})` where there's a `ParenExpr` involved, but I am not certain that's a case we have to worry about.
I think `({1,2,3})` is not a valid initializer.
implicit-int-float-narrowing.cpp:6:16: warning: expression result unused [-Wunused-value]
  int a[3] = ({1,2,3});
implicit-int-float-narrowing.cpp:6:18: warning: expression result unused [-Wunused-value]
  int a[3] = ({1,2,3});
implicit-int-float-narrowing.cpp:6:21: error: expected ';' after expression
  int a[3] = ({1,2,3});
implicit-int-float-narrowing.cpp:6:7: error: array initializer must be an initializer list
  int a[3] = ({1,2,3});
If so, I don think we need to worry about there's a `ParenExpr` involved.



More information about the cfe-commits mailing list