[clang-tidy] Improve the misc-unused-alias-decl message
authorAlexander Kornienko <alexfh@google.com>
Mon, 3 Aug 2015 22:02:08 +0000 (22:02 +0000)
committerAlexander Kornienko <alexfh@google.com>
Mon, 3 Aug 2015 22:02:08 +0000 (22:02 +0000)
"this namespace alias decl is unused" -> "namespace alias decl '...' is unused"

llvm-svn: 243906

clang-tools-extra/clang-tidy/misc/UnusedAliasDeclsCheck.cpp
clang-tools-extra/clang-tidy/misc/UnusedAliasDeclsCheck.h
clang-tools-extra/test/clang-tidy/misc-unused-alias-decls.cpp

index 0b59692..80e4861 100644 (file)
@@ -30,7 +30,7 @@ void UnusedAliasDeclsCheck::registerMatchers(MatchFinder *Finder) {
 }
 
 void UnusedAliasDeclsCheck::check(const MatchFinder::MatchResult &Result) {
-  if (const auto *AliasDecl = Result.Nodes.getNodeAs<Decl>("alias")) {
+  if (const auto *AliasDecl = Result.Nodes.getNodeAs<NamedDecl>("alias")) {
     FoundDecls[AliasDecl] = CharSourceRange::getCharRange(
         AliasDecl->getLocStart(),
         Lexer::findLocationAfterToken(
@@ -52,7 +52,8 @@ void UnusedAliasDeclsCheck::onEndOfTranslationUnit() {
   for (const auto &FoundDecl : FoundDecls) {
     if (!FoundDecl.second.isValid())
       continue;
-    diag(FoundDecl.first->getLocation(), "this namespace alias decl is unused")
+    diag(FoundDecl.first->getLocation(), "namespace alias decl '%0' is unused")
+        << FoundDecl.first->getName()
         << FixItHint::CreateRemoval(FoundDecl.second);
   }
 }
index 3cbaecd..770038f 100644 (file)
@@ -25,7 +25,7 @@ public:
   void onEndOfTranslationUnit() override;
 
 private:
-  llvm::DenseMap<const Decl *, CharSourceRange> FoundDecls;
+  llvm::DenseMap<const NamedDecl *, CharSourceRange> FoundDecls;
 };
 
 } // namespace tidy
index 01d6d9a..46527e4 100644 (file)
@@ -6,7 +6,7 @@ class C {};
 }
 
 namespace unused_alias = ::my_namespace; // eol-comments aren't removed (yet)
-// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: this namespace alias decl is unused
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: namespace alias decl 'unused_alias' is unused
 // CHECK-FIXES: {{^}}// eol-comments aren't removed (yet)
 
 namespace used_alias = ::my_namespace;