[PATCH] D27621: [clang-tidy] check to find declarations declaring more than one name

Malcolm Parsons via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Dec 11 13:38:42 PST 2016


malcolm.parsons added inline comments.


================
Comment at: clang-tidy/readability/OneNamePerDeclarationCheck.cpp:48
+  // Single declarations and macros will be ignored
+  if (DeclStmt->isSingleDecl() || DeclStmt->getLocStart().isMacroID())
+    return;
----------------
Can you reject single decls in the matcher? e.g. `unless(declCountIs(1))`.


================
Comment at: clang-tidy/readability/OneNamePerDeclarationCheck.cpp:71
+  // - and so on...
+  for (auto It = DeclStmt->getDeclGroup().begin();
+       It != DeclStmt->getDeclGroup().end(); ++It) {
----------------
`DeclStmt->getDeclGroup()` is repeated several times.
Store it in a variable.


================
Comment at: clang-tidy/readability/OneNamePerDeclarationCheck.cpp:76
+
+    if (const clang::DeclaratorDecl *DecDecl =
+            llvm::dyn_cast<const clang::DeclaratorDecl>(*It)) {
----------------
`auto *`


================
Comment at: clang-tidy/readability/OneNamePerDeclarationCheck.cpp:79
+      VariableLocation.setEnd(DecDecl->getLocEnd());
+    } else if (const clang::TypedefDecl *TypeDecl =
+                   llvm::dyn_cast<const clang::TypedefDecl>(*It)) {
----------------
`auto *`


================
Comment at: clang-tidy/readability/OneNamePerDeclarationCheck.cpp:109
+    // http://lists.llvm.org/pipermail/cfe-dev/2016-November/051425.html
+    if (const clang::VarDecl *VarDecl =
+            llvm::dyn_cast<const clang::VarDecl>(*It)) {
----------------
`auto *`


================
Comment at: clang-tidy/readability/OneNamePerDeclarationCheck.cpp:167
+    Type = FirstVar->getType();
+  } else if (const auto FirstVar =
+                 llvm::dyn_cast<const clang::TypedefDecl>(*FirstVarIt)) {
----------------
`auto *`


================
Comment at: clang-tidy/readability/OneNamePerDeclarationCheck.cpp:214
+
+  if (const MemberPointerType *T = Type->getAs<MemberPointerType>()) {
+    auto Pos = UserWrittenType.find("::");
----------------
`auto *`


================
Comment at: clang-tidy/readability/OneNamePerDeclarationCheck.cpp:246
+
+static std::string getCurrentLineIndent(SourceLocation Loc,
+                                        const SourceManager &SM) {
----------------
Should checks care about formatting, or leave to clang-format?


================
Comment at: docs/clang-tidy/checks/readability-one-name-per-declaration.rst:46
+    
+    typdef int ta;
+    typdef int tb;
----------------
`typedef`


https://reviews.llvm.org/D27621





More information about the cfe-commits mailing list