From b91e6f6f40864d54903d707d7f19a9732188b670 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Nowacki?= Date: Tue, 12 Mar 2019 09:22:15 +0100 Subject: [PATCH] Issue a warning about unused result of qScopeGuard and QScopeGuard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the result is unassigned then resulting QScopeGuard is destroyed immediately, we can warn about it, as it is definitely a bug. Change-Id: I627b05cecb3d0e62dbc24373e621f2be36d9b324 Reviewed-by: Qt CI Bot Reviewed-by: MÃ¥rten Nordheim --- src/corelib/tools/qscopeguard.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/corelib/tools/qscopeguard.h b/src/corelib/tools/qscopeguard.h index 31100fcabb..0f61996eb6 100644 --- a/src/corelib/tools/qscopeguard.h +++ b/src/corelib/tools/qscopeguard.h @@ -50,7 +50,12 @@ template class QScopeGuard; template QScopeGuard qScopeGuard(F f); template -class QScopeGuard +class +#ifndef __INTEL_COMPILER +// error #2621: attribute "__warn_unused_result__" does not apply here +Q_REQUIRED_RESULT +#endif +QScopeGuard { public: QScopeGuard(QScopeGuard &&other) Q_DECL_NOEXCEPT @@ -86,6 +91,10 @@ private: template +#ifndef __INTEL_COMPILER +// Causes "error #3058: GNU attributes on a template redeclaration have no effect" +Q_REQUIRED_RESULT +#endif QScopeGuard qScopeGuard(F f) { return QScopeGuard(std::move(f));