[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] PATCH: use std::uncaught_exceptions()

From: Vadim Zeitlin
Subject: Re: [lmi] PATCH: use std::uncaught_exceptions()
Date: Mon, 26 Mar 2018 17:47:10 +0200

On Sun, 25 Mar 2018 23:30:06 +0000 Greg Chicares <address@hidden> wrote:

GC> That glow faded quickly...

 Sorry, I did think about this problem, but decided not to mention it to
avoid mudding waters in my previous reply. With the benefit of hindsight, I
should have done it and saved you some time...

GC> >  To summarize, my preferred solution would be to continue calling EndDoc()
GC> > from the dtor automatically, but skip doing it during stack unwinding.
GC> I tried implementing it myself. I'm sure you could do it faster, but by
GC> doing it myself I might grow comfortable with the technique. Here's
GC> what I tried: of four hunks changed, I really only want the last two,
GC> and the first two are just my failed attempts to fix the errors.

 I think gcc is correct and the code, as written, is really invalid, but
the problem is that its error messages are just poor. Compare them with
what clang gives for the same code:

% make libskeleton_la-ledger_pdf_generator_wx.lo
  CXX      libskeleton_la-ledger_pdf_generator_wx.lo
/home/zeitlin/src/lmi/ledger_pdf_generator_wx.cpp:658:13: error: exception 
specification of explicitly defaulted destructor does not match the calculated 
    virtual ~page() noexcept(false) = default;
1 error generated.

This is indeed clear enough and points to the fix: if noexcept(false) is
used, we can't use "= default", as this implies noexcept(true). So the
working patch is just:

---------------------------------- >8 --------------------------------------
diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index 20a482564..5ba2baf40 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -655,7 +655,7 @@ class page
     page& operator=(page const&) = delete;

     // Make base class dtor virtual.
-    virtual ~page() = default;
+    virtual ~page() noexcept(false) {}

     // Associate the illustration object using this page with it.
@@ -1191,7 +1191,7 @@ class numbered_page : public page_with_footer
         last_page_number_ += extra_pages_;

-    ~numbered_page() override
+    ~numbered_page() noexcept(false) override
         // Check that next_page() was called the expected number of times,
         // unless we're unwinding the stack due to some other error, in which
---------------------------------- >8 --------------------------------------

 Moreover, the second chunk is not really necessary, declaring the base
class dtor as noexcept(false) is sufficient for the derived ones to also be
noexcept(false) by default, I've only included it for clarity and to ensure
that the code stops compiling if noexcept(false) is ever removed from the
base class dtor.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]