[PATCH] D53488: [clang-tidy] Improving narrowing conversions

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 9 10:05:40 PST 2018


aaron.ballman added inline comments.


================
Comment at: clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp:108-113
+  if (T.isSignedInteger())
+    return {llvm::APSInt::getMinValue(Context.getTypeSize(&T), false),
+            llvm::APSInt::getMaxValue(Context.getTypeSize(&T), false)};
+  assert(T.isUnsignedInteger() && "Unhandled BuiltinType");
+  return {llvm::APSInt::getMinValue(Context.getTypeSize(&T), true),
+          llvm::APSInt::getMaxValue(Context.getTypeSize(&T), true)};
----------------
This can be further simplified into:
```
  assert(T.isInteger() && "Unexpected builtin type");
  return {llvm::APSInt::getMinValue(Context.getTypeSize(&T), T.isUnsignedInteger()),
           llvm::APSInt::getMaxValue(Context.getTypeSize(&T), T.isUnsignedInteger())};
```


================
Comment at: clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp:313
+    // We create variables so we make sure both sides of the
+    // ConditionalOperator are evaluated, the || operator would shortciruit
+    // the second call otherwise.
----------------
shortciruit -> short circuit


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53488





More information about the cfe-commits mailing list