[PATCH] D46535: Correct warning on Float->Integer conversions.

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 7 13:26:30 PDT 2018


aaron.ballman added inline comments.


================
Comment at: lib/Sema/SemaChecking.cpp:9432
   if (IsLiteral) {
+    // Conversion of a floating point value to a non-bool integer where the
+    // integral part cannot be represented by the integer type is undefined.
----------------
floating point -> floating-point


================
Comment at: lib/Sema/SemaChecking.cpp:9440-9441
+            diag::warn_impcast_literal_float_to_integer_out_of_range);
+      if (IntegerValue.isUnsigned() &&
+          (IntegerValue.isMaxValue() || IntegerValue.isMinValue()))
+        return DiagnoseImpCast(
----------------
I think you can combine all of the predicates into:
```
if (!IsBool && ((IntegerValue.isSigned() && (...) || (IntegerValue.isUnsigned() && (...))))
  return DiagnoseImpCast(S, E, T, CContext, diag::warn_impcast_literal_float_to_integer_out_of_range);
```


Repository:
  rC Clang

https://reviews.llvm.org/D46535





More information about the cfe-commits mailing list