[PATCH] D24656: [clang-tidy] Add check readability-redundant-declaration

Daniel Marjamäki via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 28 05:03:27 PDT 2016


danielmarjamaki marked 3 inline comments as done.

================
Comment at: clang-tidy/readability/RedundantDeclarationCheck.cpp:39
@@ +38,3 @@
+  bool MultiVar = false;
+  if (const auto *VD = dyn_cast<VarDecl>(D)) {
+    if (VD && VD->getPreviousDecl()->getStorageClass() == SC_Extern &&
----------------
I don't want to generate a fixit. because it could easily break the code. And it will probably depend on inclusion order.

================
Comment at: clang-tidy/readability/RedundantDeclarationCheck.cpp:45
@@ +44,3 @@
+    for (const auto Other : VD->getDeclContext()->decls()) {
+      if (Other != D && Other->getLocStart() == VD->getLocStart()) {
+        MultiVar = true;
----------------
I think this is better. But not perfect. Maybe there is still a better way.

================
Comment at: clang-tidy/readability/RedundantDeclarationCheck.cpp:59-65
@@ +58,9 @@
+  {
+    auto Diag = diag(D->getLocation(), "redundant '%0' declaration")
+        << cast<NamedDecl>(D)->getName();
+    if (!MultiVar && !DifferentHeaders)
+      Diag << FixItHint::CreateRemoval(
+               SourceRange(D->getSourceRange().getBegin(), EndLoc));
+  }
+  diag(Prev->getLocation(), "previously declared here", DiagnosticIDs::Note);
+}
----------------
Thanks! That works.


https://reviews.llvm.org/D24656





More information about the cfe-commits mailing list