]> granicus.if.org Git - clang/commitdiff
Destroy the diagnostic client first in ~DiagnosticEngine
authorReid Kleckner <reid@kleckner.net>
Wed, 17 Dec 2014 20:23:11 +0000 (20:23 +0000)
committerReid Kleckner <reid@kleckner.net>
Wed, 17 Dec 2014 20:23:11 +0000 (20:23 +0000)
Add a comment and a test to ~DiagnosticEngine about the ordering
requirements on the teardown of DiagnosticConsumer. This could also be
accomplished by rearranging the fields of ~DiagnosticEngine, but I felt
that this was a better, more explicit solution.

This fixes PR21911, an issue that occurred after the unique_ptr
migration in r222193.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@224454 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/Diagnostic.h
lib/Basic/Diagnostic.cpp
test/Frontend/verify-unknown-arg.c [new file with mode: 0644]

index 31a29fa200720863c895b7b6bd87e428d7412cc2..91e94db802b19fbdc867f0a00e22f912eaa2f00f 100644 (file)
@@ -347,6 +347,7 @@ public:
                       DiagnosticOptions *DiagOpts,
                       DiagnosticConsumer *client = nullptr,
                       bool ShouldOwnClient = true);
+  ~DiagnosticsEngine();
 
   const IntrusiveRefCntPtr<DiagnosticIDs> &getDiagnosticIDs() const {
     return Diags;
index 5c066efa1083e87f52c210674b4a772dab318ded..a8929466084d637211bc3f65a784d7cb348f4fc7 100644 (file)
@@ -61,6 +61,12 @@ DiagnosticsEngine::DiagnosticsEngine(
   Reset();
 }
 
+DiagnosticsEngine::~DiagnosticsEngine() {
+  // If we own the diagnostic client, destroy it first so that it can access the
+  // engine from its destructor.
+  setClient(nullptr);
+}
+
 void DiagnosticsEngine::setClient(DiagnosticConsumer *client,
                                   bool ShouldOwnClient) {
   Owner.reset(ShouldOwnClient ? client : nullptr);
diff --git a/test/Frontend/verify-unknown-arg.c b/test/Frontend/verify-unknown-arg.c
new file mode 100644 (file)
index 0000000..5767dae
--- /dev/null
@@ -0,0 +1,6 @@
+// RUN: not %clang_cc1 -asdf -verify %s 2>&1 | FileCheck %s
+
+// expected-no-diagnostics
+
+//      CHECK: error: 'error' diagnostics seen but not expected:
+// CHECK-NEXT: (frontend): unknown argument: '-asdf'