summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2019-10-23 16:58:26 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2019-11-08 14:24:55 +0000
commit576c8126ab569020b6396134570190525567e36f (patch)
treecbf468b3a13c2ddbde2e71fb0572e524f4039b36 /src/corelib/tools
parentdd1bb0de7b141c3f37068b49b0181ec829dc1aee (diff)
Avoid erroneous creation of QScopedValueRollback objects
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<Foo>(bar, baz); which rolls back instantly, when it should be QScopedValueRollback<Foo> blah(bar, baz); which rolls back at the end of the scope. Change-Id: I00269fe325b804078bd0a9d5058c941af7ba5597 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qscopedvaluerollback.h6
1 files changed, 5 insertions, 1 deletions
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 <typename T>
-class QScopedValueRollback
+class
+#if QT_HAS_CPP_ATTRIBUTE(nodiscard) && __cplusplus >= 201703L
+[[nodiscard]]
+#endif
+QScopedValueRollback
{
public:
explicit QScopedValueRollback(T &var)