Clear the diagnostic buffer after flushing it.
authorAlexander Kornienko <alexfh@google.com>
Fri, 3 Jan 2014 15:34:40 +0000 (15:34 +0000)
committerAlexander Kornienko <alexfh@google.com>
Fri, 3 Jan 2014 15:34:40 +0000 (15:34 +0000)
Reviewers: klimek

Reviewed By: klimek

CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D2504

llvm-svn: 198423

clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h

index 5433787..d941f74 100644 (file)
@@ -115,19 +115,23 @@ public:
   // more generic and should be pulled out into a more useful Diagnostics
   // library.
   virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
-                                const Diagnostic &Info) {
+                                const Diagnostic &Info) LLVM_OVERRIDE {
     if (DiagLevel != DiagnosticsEngine::Note) {
       Errors.push_back(ClangTidyError(getMessage(Info)));
     } else {
+      assert(!Errors.empty() &&
+             "A diagnostic note can only be appended to a message.");
       Errors.back().Notes.push_back(getMessage(Info));
     }
     addFixes(Info, Errors.back());
   }
 
-  virtual void finish() {
+  // Flushes the internal diagnostics buffer to the ClangTidyContext.
+  virtual void finish() LLVM_OVERRIDE {
     for (unsigned i = 0, e = Errors.size(); i != e; ++i) {
       Context.storeError(Errors[i]);
     }
+    Errors.clear();
   }
 
 private: