Index: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h =================================================================== --- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h +++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h @@ -138,7 +138,7 @@ /// \brief Returns the name of the clang-tidy check which produced this /// diagnostic ID. - StringRef getCheckName(unsigned DiagnosticID) const; + std::string getCheckName(unsigned DiagnosticID) const; /// \brief Returns \c true if the check is enabled for the \c CurrentFile. /// Index: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp +++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp @@ -254,7 +254,11 @@ return WarningAsErrorFilter->contains(CheckName); } -StringRef ClangTidyContext::getCheckName(unsigned DiagnosticID) const { +std::string ClangTidyContext::getCheckName(unsigned DiagnosticID) const { + std::string ClangWarningOption = + DiagEngine->getDiagnosticIDs()->getWarningOptionForDiag(DiagnosticID); + if (!ClangWarningOption.empty()) + return "clang-diagnostic-" + ClangWarningOption; llvm::DenseMap::const_iterator I = CheckNamesByDiagnosticID.find(DiagnosticID); if (I != CheckNamesByDiagnosticID.end()) @@ -305,7 +309,7 @@ Line.substr(BracketIndex, BracketEndIndex - BracketIndex); // Allow disabling all the checks with "*". if (ChecksStr != "*") { - StringRef CheckName = Context.getCheckName(DiagID); + std::string CheckName = Context.getCheckName(DiagID); // Allow specifying a few check names, delimited with comma. SmallVector Checks; ChecksStr.split(Checks, ',', -1, false); @@ -402,13 +406,7 @@ "A diagnostic note can only be appended to a message."); } else { finalizeLastError(); - StringRef WarningOption = - Context.DiagEngine->getDiagnosticIDs()->getWarningOptionForDiag( - Info.getID()); - std::string CheckName = !WarningOption.empty() - ? ("clang-diagnostic-" + WarningOption).str() - : Context.getCheckName(Info.getID()).str(); - + std::string CheckName = Context.getCheckName(Info.getID()); if (CheckName.empty()) { // This is a compiler diagnostic without a warning option. Assign check // name based on its level. Index: clang-tools-extra/trunk/test/clang-tidy/nolint.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/nolint.cpp +++ clang-tools-extra/trunk/test/clang-tidy/nolint.cpp @@ -31,6 +31,7 @@ int i; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: unused variable 'i' [clang-diagnostic-unused-variable] int j; // NOLINT + int k; // NOLINT(clang-diagnostic-unused-variable) } #define MACRO(X) class X { X(int i); }; @@ -47,4 +48,4 @@ #define DOUBLE_MACRO MACRO(H) // NOLINT DOUBLE_MACRO -// CHECK-MESSAGES: Suppressed 12 warnings (12 NOLINT) +// CHECK-MESSAGES: Suppressed 13 warnings (13 NOLINT)