Index: clang-tidy/ClangTidy.cpp =================================================================== --- clang-tidy/ClangTidy.cpp +++ clang-tidy/ClangTidy.cpp @@ -209,7 +209,7 @@ // FIXME: Move this to a separate method, so that CreateASTConsumer doesn't // modify Compiler. Context.setSourceManager(&Compiler.getSourceManager()); - Context.setCurrentFile(File); + Context.setCurrentFile(File, &Compiler.getASTContext()); std::vector> Checks; ChecksFilter &Filter = Context.getChecksFilter(); Index: clang-tidy/ClangTidyDiagnosticConsumer.h =================================================================== --- clang-tidy/ClangTidyDiagnosticConsumer.h +++ clang-tidy/ClangTidyDiagnosticConsumer.h @@ -19,6 +19,7 @@ namespace clang { +class ASTContext; class CompilerInstance; namespace ast_matchers { class MatchFinder; @@ -134,7 +135,7 @@ void setSourceManager(SourceManager *SourceMgr); /// \brief Should be called when starting to process new translation unit. - void setCurrentFile(StringRef File); + void setCurrentFile(StringRef File, ASTContext *Context); /// \brief Returns the name of the clang-tidy check which produced this /// diagnostic ID. Index: clang-tidy/ClangTidyDiagnosticConsumer.cpp =================================================================== --- clang-tidy/ClangTidyDiagnosticConsumer.cpp +++ clang-tidy/ClangTidyDiagnosticConsumer.cpp @@ -18,6 +18,7 @@ #include "ClangTidyDiagnosticConsumer.h" #include "ClangTidyOptions.h" +#include "clang/AST/ASTDiagnostic.h" #include "clang/Basic/DiagnosticOptions.h" #include "clang/Frontend/DiagnosticRenderer.h" #include "llvm/ADT/SmallString.h" @@ -163,7 +164,7 @@ : DiagEngine(nullptr), OptionsProvider(OptionsProvider) { // Before the first translation unit we can get errors related to command-line // parsing, use empty string for the file name in this case. - setCurrentFile(""); + setCurrentFile("", nullptr); } DiagnosticBuilder ClangTidyContext::diag( @@ -199,9 +200,21 @@ DiagEngine->setSourceManager(SourceMgr); } -void ClangTidyContext::setCurrentFile(StringRef File) { +static void DummyArgToStringFn(DiagnosticsEngine::ArgumentKind, intptr_t, + StringRef, StringRef, + ArrayRef, + SmallVectorImpl &Output, void *, + ArrayRef) { + StringRef Str = ""; + Output.append(Str.begin(), Str.end()); +} + +void ClangTidyContext::setCurrentFile(StringRef File, ASTContext *Context) { CurrentFile = File; CheckFilter.reset(new ChecksFilter(getOptions().Checks)); + DiagEngine->SetArgToStringFn(Context ? &FormatASTNodeDiagnosticArgument + : &DummyArgToStringFn, + Context); } const ClangTidyGlobalOptions &ClangTidyContext::getGlobalOptions() const {