[PATCH] D18783: [clang-tidy] add new checker for string literal with NUL character.

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 7 02:20:42 PDT 2016


alexfh added a comment.

A couple of nits.


================
Comment at: clang-tidy/misc/MisplacedWideningCastCheck.cpp:64
@@ -62,5 +63,3 @@
     unsigned RHSWidth = getMaxCalculationWidth(Context, Bop->getRHS());
-    if (Bop->getOpcode() == BO_Mul)
-      return LHSWidth + RHSWidth;
-    if (Bop->getOpcode() == BO_Add)
-      return std::max(LHSWidth, RHSWidth) + 1;
+    if (Bop->getOpcode() == BO_Mul) return LHSWidth + RHSWidth;
+    if (Bop->getOpcode() == BO_Add) return std::max(LHSWidth, RHSWidth) + 1;
----------------
If clang-format did this, it used an incorrect style. In LLVM style it should put `return` on the next line. It should do the right thing, if you run it with `-style=file` and your clang-tools-extra working copy is checked out inside the cfe working copy (the important part here is that there's clang's or llvm's .clang-format file in a parent directory of the files you're running clang-format on).

================
Comment at: clang-tidy/misc/MisplacedWideningCastCheck.cpp:95
@@ -96,40 +94,3 @@
 
-static llvm::SmallDenseMap<int, int> createRelativeIntSizesMap() {
-  llvm::SmallDenseMap<int, int> Result;
-  Result[BuiltinType::UChar] = 1;
-  Result[BuiltinType::SChar] = 1;
-  Result[BuiltinType::Char_U] = 1;
-  Result[BuiltinType::Char_S] = 1;
-  Result[BuiltinType::UShort] = 2;
-  Result[BuiltinType::Short] = 2;
-  Result[BuiltinType::UInt] = 3;
-  Result[BuiltinType::Int] = 3;
-  Result[BuiltinType::ULong] = 4;
-  Result[BuiltinType::Long] = 4;
-  Result[BuiltinType::ULongLong] = 5;
-  Result[BuiltinType::LongLong] = 5;
-  Result[BuiltinType::UInt128] = 6;
-  Result[BuiltinType::Int128] = 6;
-  return Result;
-}
-
-static llvm::SmallDenseMap<int, int> createRelativeCharSizesMap() {
-  llvm::SmallDenseMap<int, int> Result;
-  Result[BuiltinType::UChar] = 1;
-  Result[BuiltinType::SChar] = 1;
-  Result[BuiltinType::Char_U] = 1;
-  Result[BuiltinType::Char_S] = 1;
-  Result[BuiltinType::Char16] = 2;
-  Result[BuiltinType::Char32] = 3;
-  return Result;
-}
-
-static llvm::SmallDenseMap<int, int> createRelativeCharSizesWMap() {
-  llvm::SmallDenseMap<int, int> Result;
-  Result[BuiltinType::UChar] = 1;
-  Result[BuiltinType::SChar] = 1;
-  Result[BuiltinType::Char_U] = 1;
-  Result[BuiltinType::Char_S] = 1;
-  Result[BuiltinType::WChar_U] = 2;
-  Result[BuiltinType::WChar_S] = 2;
-  return Result;
+static int RelativeIntSizes(BuiltinType::Kind kind) {
+  switch (kind) {
----------------
s/RelativeIntSizes/relativeIntSize/ (singular, first character should be lower-case).

================
Comment at: clang-tidy/misc/MisplacedWideningCastCheck.cpp:223
@@ -201,4 +222,3 @@
 
-} // namespace misc
-} // namespace tidy
-} // namespace clang
+}  // namespace misc
+}  // namespace tidy
----------------
Two spaces before comments are common for Google style, so your clang-format most certainly uses a wrong style.


http://reviews.llvm.org/D18783





More information about the cfe-commits mailing list