diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index b68c96c7182..97dde132366 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -392,11 +392,10 @@ inline QDebugIfHasDebugStreamContainer, Key, T> operator<<(QD template inline QDebugIfHasDebugStream operator<<(QDebug debug, const std::optional &opt) { - const QDebugStateSaver saver(debug); if (!opt) - debug.nospace() << std::nullopt; - else - debug.nospace() << "std::optional(" << *opt << ')'; + return debug << std::nullopt; + const QDebugStateSaver saver(debug); + debug.nospace() << "std::optional(" << *opt << ')'; return debug; }