[PATCH] [clang-tidy] Add a checker that suggests replacing short/long/long long with fixed-size types.

Alexander Kornienko alexfh at google.com
Fri Aug 29 09:13:11 PDT 2014


REPOSITORY
  rL LLVM

================
Comment at: clang-tidy/google/IntegerTypesCheck.cpp:86
@@ +85,3 @@
+  const char *Data = Result.SourceManager->getCharacterData(Loc);
+  if (!std::strncmp(Data, Port.data(), Port.size()) &&
+      !isIdentifierBody(Data[Port.size()]))
----------------
`static const StringRef` would save some strlen calls.

Also, when I was asking about StringRef, I had a thought that it could help avoiding std::strncmp. I was wrong, so StringRef doesn't make things any better. My bad. But it was a question, not a request to change it.

================
Comment at: clang-tidy/google/IntegerTypesCheck.cpp:97
@@ +96,3 @@
+  // QualTypes are printed with implicit quotes.
+  diag(Loc, "consider replacing %0 with '%1'") << BuiltinLoc.getType()
+                                               << Replacement;
----------------
We should somehow hint the user, which header the new types are in.

================
Comment at: clang-tidy/google/IntegerTypesCheck.h:19
@@ +18,3 @@
+
+/// \brief Finds uses of short, long and long long and suggest replacing them
+/// with u?intXX(_t)?.
----------------
It also finds unsigned versions of these, right?

================
Comment at: clang-tidy/google/IntegerTypesCheck.h:26
@@ +25,3 @@
+      : UnsignedTypePrefix("uint"), SignedTypePrefix("int"),
+        AddUnderscoreT(false) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
----------------
I think, it makes sense noting that we need "_t" for standard types defined in <stdint.h>.

http://reviews.llvm.org/D5119






More information about the cfe-commits mailing list