[PATCH] D18919: [Clang-tidy] Add check "modernize use using"

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 24 11:34:02 PDT 2016


hokein added inline comments.

================
Comment at: clang-tidy/modernize/ModernizeTidyModule.cpp:49
@@ -47,1 +48,3 @@
     CheckFactories.registerCheck<UseOverrideCheck>("modernize-use-override");
+    CheckFactories.registerCheck<UseUsingCheck>(
+        "modernize-use-using");
----------------
You can put it in one-line, which will not exceed 80 characters.

================
Comment at: clang-tidy/modernize/UseUsingCheck.cpp:23
@@ +22,3 @@
+  Finder->addMatcher(typedefDecl().bind("typedef"), this);
+}
+///Function which replace all substrings "search" with "replace" in string "s"
----------------
Add a blank line.

================
Comment at: clang-tidy/modernize/UseUsingCheck.cpp:24
@@ +23,3 @@
+}
+///Function which replace all substrings "search" with "replace" in string "s"
+static void replaceAll(std::string &s, const std::string &search, const std::string replace){
----------------
A blank between `///` and `F`, please use clang-format to make sure your code align with LLVM style.

================
Comment at: clang-tidy/modernize/UseUsingCheck.cpp:25
@@ +24,3 @@
+///Function which replace all substrings "search" with "replace" in string "s"
+static void replaceAll(std::string &s, const std::string &search, const std::string replace){
+  size_t pos = 0;
----------------
`replace` parameter can be `const std::string&`.

================
Comment at: clang-tidy/modernize/UseUsingCheck.cpp:26
@@ +25,3 @@
+static void replaceAll(std::string &s, const std::string &search, const std::string replace){
+  size_t pos = 0;
+    while ((pos = s.find(search, pos)) != std::string::npos) {
----------------
code indentation.  

================
Comment at: clang-tidy/modernize/UseUsingCheck.cpp:38
@@ +37,3 @@
+      {" class ", ""}, {"(class ", "("}, {"struct ", ""}, {"union ", ""}, {"(void)", "()"}};
+  for (auto p : Subs) {
+    std::string search = p.first;
----------------
`const auto &p`

================
Comment at: clang-tidy/modernize/UseUsingCheck.cpp:41
@@ +40,3 @@
+    std::string replace = p.second;
+    replaceAll(subject, search, replace);
+  }
----------------
You can use `replaceAll(subject, p.first, p.second)`.

================
Comment at: clang-tidy/modernize/UseUsingCheck.cpp:46
@@ +45,3 @@
+
+void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *MatchedDecl = Result.Nodes.getNodeAs<TypedefDecl>("typedef");
----------------
You need to filter out the non-c++11 code here.

================
Comment at: clang-tidy/modernize/UseUsingCheck.h:19
@@ +18,3 @@
+
+/// Finds typedefs and replaces it with using
+///
----------------
Please use a complete sentence.

================
Comment at: test/clang-tidy/modernize-use-using.cpp:2
@@ +1,3 @@
+// RUN: %check_clang_tidy %s modernize-use-using %t
+
+
----------------
Remove the extra blank line.

================
Comment at: test/clang-tidy/modernize-use-using.cpp:9
@@ +8,3 @@
+typedef long LL;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using LL = long;
----------------
No need to check the whole message except the first one. So here you can use `warning: use using instead of typedef`.


Repository:
  rL LLVM

http://reviews.llvm.org/D18919





More information about the cfe-commits mailing list