Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: tools/clang/plugins/SuppressibleDiagnosticBuilder.h

Issue 1385193002: Bisect clang Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 246985 Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/clang/plugins/README.chromium ('k') | tools/clang/plugins/tests/base_refcounted.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef TOOLS_CLANG_PLUGINS_HESIENDIAGNOSTICBUILDER_H_
6 #define TOOLS_CLANG_PLUGINS_HESIENDIAGNOSTICBUILDER_H_
7
8 #include "clang/Basic/Diagnostic.h"
9 #include "clang/Basic/SourceLocation.h"
10
11 namespace chrome_checker {
12
13 // A simple wrapper around DiagnosticBuilder that allows a diagnostic to be
14 // suppressed. The intended use case is for helper functions that return a
15 // DiagnosticBuilder, but only want to emit the diagnostic if some conditions
16 // are met.
17 class SuppressibleDiagnosticBuilder : public clang::DiagnosticBuilder {
18 public:
19 SuppressibleDiagnosticBuilder(clang::DiagnosticsEngine* diagnostics,
20 clang::SourceLocation loc,
21 unsigned diagnostic_id,
22 bool suppressed)
23 : DiagnosticBuilder(diagnostics->Report(loc, diagnostic_id)),
24 diagnostics_(diagnostics),
25 suppressed_(suppressed) {}
26
27 ~SuppressibleDiagnosticBuilder() {
28 if (suppressed_) {
29 // Clear the counts and underlying data, so the base class destructor
30 // doesn't try to emit the diagnostic.
31 FlushCounts();
32 Clear();
33 // Also clear the current diagnostic being processed by the
34 // DiagnosticsEngine, since it won't be emitted.
35 diagnostics_->Clear();
36 }
37 }
38
39 template <typename T>
40 friend const SuppressibleDiagnosticBuilder& operator<<(
41 const SuppressibleDiagnosticBuilder& builder,
42 const T& value) {
43 const DiagnosticBuilder& base_builder = builder;
44 base_builder << value;
45 return builder;
46 }
47
48 private:
49 clang::DiagnosticsEngine* const diagnostics_;
50 const bool suppressed_;
51 };
52
53 } // namespace chrome_checker
54
55 #endif // TOOLS_CLANG_PLUGINS_HESIENDIAGNOSTICBUILDER_H_
OLDNEW
« no previous file with comments | « tools/clang/plugins/README.chromium ('k') | tools/clang/plugins/tests/base_refcounted.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698