QT stopped compiling with QT_NO_EXCEPTIONS

QT 6.7.2 failed to build with QT_NO_EXCEPTIONS for Android with the following errors:

C:/dev/repos/qt-everywhere-src-6.7.2/qtbase/src/corelib/io/qprocess_unix.cpp:889:29: error: use of undeclared identifier 'e'
        failChildProcess(d, e.what(), FakeErrnoForThrow);
                            ^
C:/dev/repos/qt-everywhere-src-6.7.2/qtbase/src/corelib/io/qprocess_unix.cpp:890:7: error: expected expression
    } QT_CATCH (...) {
      ^
C:/dev/repos/qt-everywhere-src-6.7.2/qtbase/src/corelib/global/qexceptionhandling.h:28:23: note: expanded from macro 'QT_CATCH'
#  define QT_CATCH(A) else
                      ^
2 errors generated.
[673/5992] Building CXX object qtbase/src/corelib/CMakeFiles/Core.dir/itemmodels/qabstractitemmodel.cpp.o
ninja: build stopped: subcommand failed.

qt-everywhere-src-6.7.2\qtbase\src\corelib\io\qprocess_unix.cpp:

// the noexcept here adds an extra layer of protection
static void callChildProcessModifier(const QProcessPrivate *d) noexcept
{
    QT_TRY {
        if (d->unixExtras->childProcessModifier)
            d->unixExtras->childProcessModifier();
    } QT_CATCH (std::exception &e) {
        failChildProcess(d, e.what(), FakeErrnoForThrow);
    } QT_CATCH (...) {
        failChildProcess(d, "throw", FakeErrnoForThrow);
    }
}

The definitions of QT_TRY and QT_CATCH:

#ifdef QT_NO_EXCEPTIONS
#  define QT_TRY if (true)
#  define QT_CATCH(A) else
#  define QT_THROW(A) qt_noop()
#  define QT_RETHROW qt_noop()
#  define QT_TERMINATE_ON_EXCEPTION(expr) do { expr; } while (false)
#else
#  define QT_TRY try
#  define QT_CATCH(A) catch (A)
#  define QT_THROW(A) throw A
#  define QT_RETHROW throw
#  ifdef Q_COMPILER_NOEXCEPT
#    define QT_TERMINATE_ON_EXCEPTION(expr) do { expr; } while (false)
#  else
#    define QT_TERMINATE_ON_EXCEPTION(expr) do { try { expr; } catch (...) { qTerminate(); } } while (false)
#  endif
#endif

Workaround

I tried to simply replace line 889 with

    failChildProcess(d, "e.what() workaround", FakeErrnoForThrow);

but got:

C:/dev/repos/qt-everywhere-src-6.7.2/qtbase/src/corelib/io/qprocess_unix.cpp:890:7: error: expected expression
    } QT_CATCH (...) {
      ^
C:/dev/repos/qt-everywhere-src-6.7.2/qtbase/src/corelib/global/qexceptionhandling.h:28:23: note: expanded from macro 'QT_CATCH'
#  define QT_CATCH(A) else
                      ^
1 error generated.
[639/5992] Building CXX object qtbase/src/corelib/CMakeFiles/Core.dir/io/qsettings.cpp.o
ninja: build stopped: subcommand failed.

so I commented out all the try/catch block:

// the noexcept here adds an extra layer of protection
static void callChildProcessModifier(const QProcessPrivate *d) noexcept
{
    //QT_TRY {
        if (d->unixExtras->childProcessModifier)
            d->unixExtras->childProcessModifier();
    // } QT_CATCH (std::exception &e) {
    //     failChildProcess(d, "e.what() workaround", FakeErrnoForThrow);
    // } QT_CATCH (...) {
    //     failChildProcess(d, "throw", FakeErrnoForThrow);
    // }
}

2 Responses to QT stopped compiling with QT_NO_EXCEPTIONS

  1. dmitriano says:

    error: cannot pass object of non-trivial type ‘QtJniTypes::Context’ through variadic constructor
    https://forum.qt.io/topic/157520/error-cannot-pass-object-of-non-trivial-type-qtjnitypes-context-through-variadic-constructor

  2. dmitriano says:

    https://bugreports.qt.io/browse/QTBUG-126792
    Not a bug because this is not supported. Feel free to supply patches.

Leave a Reply

Your email address will not be published. Required fields are marked *