From 5b89cf209c3fb184a917355e12f589c83e9ad28f Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 22 Jun 2018 18:32:12 +0300 Subject: Use uncaught_exceptions() if available C++17 deprecated uncaught_exception() and GCC 8 now issues a warning. --- mod/diagnostics.hxx | 50 +++++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 19 deletions(-) (limited to 'mod/diagnostics.hxx') diff --git a/mod/diagnostics.hxx b/mod/diagnostics.hxx index cc3eef6..d30a5ef 100644 --- a/mod/diagnostics.hxx +++ b/mod/diagnostics.hxx @@ -6,6 +6,9 @@ #define MOD_DIAGNOSTICS_HXX #include +#include // uncaught_exception[s]() + +#include // uncaught_exceptions #include #include @@ -52,15 +55,20 @@ namespace brep return r; } - diag_record () = default; + diag_record () + : +#ifdef __cpp_lib_uncaught_exceptions + uncaught_ (std::uncaught_exceptions ()), +#endif + epilogue_ (nullptr) {} template explicit - diag_record (const diag_prologue& p) {*this << p;} // See below. + diag_record (const diag_prologue& p): diag_record () {*this << p;} template explicit - diag_record (const diag_mark& m) {*this << m;} // See below. + diag_record (const diag_mark& m): diag_record () {*this << m;} ~diag_record () noexcept(false); @@ -88,25 +96,26 @@ namespace brep // Move constructible-only type. // - /* - @@ libstdc++ doesn't yet have the ostringstream move support. - + // Older versions of libstdc++ don't have the ostringstream move support + // and accuratly detecting its version is non-trivial. So we always use + // the pessimized implementation with libstdc++. Luckily, GCC doesn't seem + // to be needing move due to copy/move elision. + // +#ifdef __GLIBCXX__ + diag_record (diag_record&&); +#else diag_record (diag_record&& r) - : data_ (move (r.data_)), os_ (move (r.os_)) + : +#ifdef __cpp_lib_uncaught_exceptions + uncaught_ (r.uncaught_), +#endif + data_ (move (r.data_)), + os_ (move (r.os_)), + epilogue_ (r.epilogue_) { - epilogue_ = r.epilogue_; - r.data_.clear (); // Empty. - } - */ - - diag_record (diag_record&& r): data_ (move (r.data_)) - { - if (!data_.empty ()) - os_ << r.os_.str (); - - epilogue_ = r.epilogue_; r.data_.clear (); // Empty. } +#endif diag_record& operator= (diag_record&&) = delete; @@ -114,9 +123,12 @@ namespace brep diag_record& operator= (const diag_record&) = delete; private: +#ifdef __cpp_lib_uncaught_exceptions + const int uncaught_; +#endif mutable diag_data data_; mutable std::ostringstream os_; - mutable const diag_epilogue* epilogue_ {nullptr}; + mutable const diag_epilogue* epilogue_; }; // Base (B) should provide operator() that configures diag_record. -- cgit v1.1