diff --git a/mkspecs/features/common_pre.prf b/mkspecs/features/common_pre.prf index 7d8062355..6fa19fdae 100644 --- a/mkspecs/features/common_pre.prf +++ b/mkspecs/features/common_pre.prf @@ -218,6 +218,10 @@ win32:llvm { equals(WORD_SIZE,32): QMAKE_CXXFLAGS += --target=i686-pc-windows-gnu equals(WORD_SIZE,64): QMAKE_CXXFLAGS += --target=x86_64-pc-windows-gnu } + else { + CONFIG += c++latest + QMAKE_CXXFLAGS_WARN_ON += -Wno-deprecated-declarations + } # Address Sanitizer # https://stackoverflow.com/a/48585886/1639256 diff --git a/src/blackmisc/atomicfile.cpp b/src/blackmisc/atomicfile.cpp index 4dd266ed1..ac5dcfa03 100644 --- a/src/blackmisc/atomicfile.cpp +++ b/src/blackmisc/atomicfile.cpp @@ -71,6 +71,16 @@ namespace BlackMisc return ok; } + CAtomicFile::~CAtomicFile() + { +#if __cplusplus >= 201700L + const bool ex = std::uncaught_exceptions() > 0; +#else + const bool ex = std::uncaught_exception(); +#endif + if (ex) { QFile::close(); } + } + void CAtomicFile::close() { if (! isOpen()) { return; } diff --git a/src/blackmisc/atomicfile.h b/src/blackmisc/atomicfile.h index 46dbce974..f979a4dba 100644 --- a/src/blackmisc/atomicfile.h +++ b/src/blackmisc/atomicfile.h @@ -38,7 +38,7 @@ namespace BlackMisc CAtomicFile(const QString &filename) : QFile(filename) {} //! \copydoc QFile::~QFile - virtual ~CAtomicFile() override { if (std::uncaught_exception()) { QFile::close(); } } + virtual ~CAtomicFile() override; //! \copydoc QFile::open //! Just before opening the file, the filename is changed so we actually write to a temporary file. diff --git a/src/blackmisc/fileutils.cpp b/src/blackmisc/fileutils.cpp index 46a70a7b1..49c09aec4 100644 --- a/src/blackmisc/fileutils.cpp +++ b/src/blackmisc/fileutils.cpp @@ -358,7 +358,7 @@ namespace BlackMisc QFileInfoList result = dir.entryInfoList(nameFilters, QDir::Files); if (predicate) { - result.erase(std::remove_if(result.begin(), result.end(), std::not1(predicate)), result.end()); + result.erase(std::remove_if(result.begin(), result.end(), [ = ](const auto &f) { return !predicate(f); }), result.end()); } if (recursive) { diff --git a/src/blackmisc/processctrl.cpp b/src/blackmisc/processctrl.cpp index 503c088d3..5426e0e99 100644 --- a/src/blackmisc/processctrl.cpp +++ b/src/blackmisc/processctrl.cpp @@ -8,7 +8,7 @@ #include "blackmisc/processctrl.h" #include "blackmisc/logmessage.h" - +#include #include #ifdef Q_OS_WIN @@ -36,7 +36,7 @@ namespace BlackMisc QString command = '"' % QString(program).replace('/', '\\') % '"'; if (!arguments.isEmpty()) { - command += " \"" % arguments.join('" "').replace('/', '\\') % '"'; + command += " \"" % arguments.join("\" \"").replace('/', '\\') % '"'; } DWORD flags = 0; diff --git a/src/blackmisc/valuecache.cpp b/src/blackmisc/valuecache.cpp index 7d81c5dc3..b22618865 100644 --- a/src/blackmisc/valuecache.cpp +++ b/src/blackmisc/valuecache.cpp @@ -571,7 +571,12 @@ namespace BlackMisc { if (m_page) { - if (std::uncaught_exception()) { m_page->abandonBatch(); } +#if __cplusplus >= 201700L + const bool ex = std::uncaught_exceptions() > 0; +#else + const bool ex = std::uncaught_exception(); +#endif + if (ex) { m_page->abandonBatch(); } else { m_page->endBatch(); } } } diff --git a/src/xswiftbus/messages.cpp b/src/xswiftbus/messages.cpp index f64226069..8374a3de1 100644 --- a/src/xswiftbus/messages.cpp +++ b/src/xswiftbus/messages.cpp @@ -78,7 +78,8 @@ namespace XSwiftBus { const int y = boxTop - (lineHeight + lineSpace) * (i + 1); const size_t ii = static_cast(i); - XPLMDrawString(m_messages[ii].m_rgb.data(), x + arrowWidth + arrowWidth / 2, y, const_cast(m_messages[ii].m_text.c_str()), nullptr, xplmFont_Basic); + XPLMDrawString(m_messages[ii].m_rgb.data(), x + arrowWidth + arrowWidth / 2, y, + const_cast(reinterpret_cast(m_messages[ii].m_text.c_str())), nullptr, xplmFont_Basic); } } @@ -109,13 +110,12 @@ namespace XSwiftBus CMessageBoxControl::CMessageBoxControl(int left, int right, int top) : m_messageBox(left, right, top), m_showCommand("org/swift-project/xswiftbus/show_messages", "Show XSwiftBus text messages", [this] { show(); }), - m_hideCommand("org/swift-project/xswiftbus/hide_messages", "Hide XSwiftBus text messages", [this] { hide(); }), - m_toggleCommand("org/swift-project/xswiftbus/toggle_messages", "Toggle XSwiftBus text messages", [this] { toggle(); }), - m_scrollUpCommand("org/swift-project/xswiftbus/scroll_up", "Scroll up XSwiftBus text messages", [this] { scrollUp(); }), - m_scrollDownCommand("org/swift-project/xswiftbus/scroll_down", "Scroll down XSwiftBus text messages", [this] { scrollDown(); }), - m_scrollToTopCommand("org/swift-project/xswiftbus/scroll_top", "Scroll to top of XSwiftBus text messages", [this] { scrollToTop(); }), - m_scrollToBottomCommand("org/swift-project/xswiftbus/scroll_bottom", "Scroll to bottom of XSwiftBus text messages", [this] { scrollToBottom(); }), - m_debugCommand("org/swift-project/xswiftbus/debug", "", [this] { static int c = 0; this->addMessage({ "hello " + std::to_string(c++), 0, .75, 0 }); }) + m_hideCommand("org/swift-project/xswiftbus/hide_messages", "Hide XSwiftBus text messages", [this] { hide(); }), + m_toggleCommand("org/swift-project/xswiftbus/toggle_messages", "Toggle XSwiftBus text messages", [this] { toggle(); }), + m_scrollUpCommand("org/swift-project/xswiftbus/scroll_up", "Scroll up XSwiftBus text messages", [this] { scrollUp(); }), + m_scrollDownCommand("org/swift-project/xswiftbus/scroll_down", "Scroll down XSwiftBus text messages", [this] { scrollDown(); }), + m_scrollToTopCommand("org/swift-project/xswiftbus/scroll_top", "Scroll to top of XSwiftBus text messages", [this] { scrollToTop(); }), + m_scrollToBottomCommand("org/swift-project/xswiftbus/scroll_bottom", "Scroll to bottom of XSwiftBus text messages", [this] { scrollToBottom(); }) { show(); } diff --git a/src/xswiftbus/messages.h b/src/xswiftbus/messages.h index 2d23e10ca..940b5cfd1 100644 --- a/src/xswiftbus/messages.h +++ b/src/xswiftbus/messages.h @@ -22,16 +22,30 @@ namespace XSwiftBus { + //! \cond + namespace Private + { + inline auto empty_u8string() + { + using namespace std::literals; + return u8""s; + } + } + //! \endcond + /*! * Class representing a single line of text to be drawn in a message box. */ struct CMessage { + //! String type. + using string = decltype(Private::empty_u8string()); + //! Constructor. - CMessage(const std::string &text, float r = 1, float g = 1, float b = 1) : m_text(text), m_rgb{{ r, g, b }} {} + CMessage(const string &text, float r = 1, float g = 1, float b = 1) : m_text(text), m_rgb{{ r, g, b }} {} //! Text. - std::string m_text; + string m_text; //! Color. std::array m_rgb; @@ -148,7 +162,6 @@ namespace XSwiftBus CCommand m_scrollDownCommand; CCommand m_scrollToTopCommand; CCommand m_scrollToBottomCommand; - CCommand m_debugCommand; }; } //ns diff --git a/src/xswiftbus/service.cpp b/src/xswiftbus/service.cpp index 53f5a33c0..64c9496a1 100644 --- a/src/xswiftbus/service.cpp +++ b/src/xswiftbus/service.cpp @@ -145,12 +145,13 @@ namespace XSwiftBus void CService::addTextMessage(const std::string &text, double red, double green, double blue) { if (text.empty()) { return; } - static const std::string ellipsis = u8"\u2026"; + static const CMessage::string ellipsis = u8"\u2026"; const int lineLength = m_messages.maxLineLength() - static_cast(ellipsis.size()); - std::vector wrappedLines; + std::vector wrappedLines; for (size_t i = 0; i < text.size(); i += static_cast(lineLength)) { - wrappedLines.push_back(text.substr(i, static_cast(lineLength)) + ellipsis); + wrappedLines.emplace_back(text.begin() + i, text.begin() + i + static_cast(lineLength)); + wrappedLines.back() += ellipsis; } wrappedLines.back().erase(wrappedLines.back().size() - ellipsis.size()); if (wrappedLines.back().empty()) { wrappedLines.pop_back(); } diff --git a/tests/blackmisc/teststringutils/teststringutils.cpp b/tests/blackmisc/teststringutils/teststringutils.cpp index 61784dfa0..2b51c95b6 100644 --- a/tests/blackmisc/teststringutils/teststringutils.cpp +++ b/tests/blackmisc/teststringutils/teststringutils.cpp @@ -161,8 +161,10 @@ namespace BlackMiscTest void CTestStringUtils::testSimplify() { - const QString input = QString::fromUtf8(u8"ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöùúûüýÿ"); - const QString output = QLatin1String("SZszYAAAAAACEEEEIIIINOOOOOUUUUYaaaaaaceeeeiiiinooooouuuuyy"); + const auto inputChars = u8"ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöùúûüýÿ"; + const auto outputChars = "SZszYAAAAAACEEEEIIIINOOOOOUUUUYaaaaaaceeeeiiiinooooouuuuyy"; + const QString input = QString::fromUtf8(reinterpret_cast(inputChars)); + const QString output = QLatin1String(outputChars); QCOMPARE(simplifyAccents(input), output); QCOMPARE(simplifyByDecomposition(input), output); }