From 576c8126ab569020b6396134570190525567e36f Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 23 Oct 2019 16:58:26 +0200 Subject: [PATCH] Avoid erroneous creation of QScopedValueRollback objects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mark the class as [[nodiscard]] to ensure that instances are given names and do not destruct (roll back) immediately. This avoids accidental code like this: QScopedValueRollback(bar, baz); which rolls back instantly, when it should be QScopedValueRollback blah(bar, baz); which rolls back at the end of the scope. Change-Id: I00269fe325b804078bd0a9d5058c941af7ba5597 Reviewed-by: Fabian Kosmale Reviewed-by: MÃ¥rten Nordheim --- src/corelib/tools/qscopedvaluerollback.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/corelib/tools/qscopedvaluerollback.h b/src/corelib/tools/qscopedvaluerollback.h index f904b8dfcb..b8ceff6665 100644 --- a/src/corelib/tools/qscopedvaluerollback.h +++ b/src/corelib/tools/qscopedvaluerollback.h @@ -45,7 +45,11 @@ QT_BEGIN_NAMESPACE template -class QScopedValueRollback +class +#if QT_HAS_CPP_ATTRIBUTE(nodiscard) && __cplusplus >= 201703L +[[nodiscard]] +#endif +QScopedValueRollback { public: explicit QScopedValueRollback(T &var)