From e5e560c7fdbd2d8c0ffef1f07add0acf738202c8 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 24 Oct 2024 14:35:32 +0200 Subject: [PATCH] QDebug: simplify op<<(std::optional) We don't need to enable nospace() if we stream but a single element (nullopt). As a consequence, delay construction of the StateSaver until we have determined that the optional is engaged. Amends b7657ddccbe0a5ab1cdfc61ae6b7f0501dbfb24a. Change-Id: Id974dff078cb989b92f84b63bf14956a2fba32b2 Reviewed-by: David Faure (cherry picked from commit 25931bf2181706e1cba416b0530f07959182f074) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/io/qdebug.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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; }