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>
This commit is contained in:
Simon Hausmann 2019-10-23 16:58:26 +02:00
parent dd1bb0de7b
commit 576c8126ab

View File

@ -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)