Skip to content

Commit

Permalink
Issue a warning about unused result of qScopeGuard and QScopeGuard
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Mårten Nordheim <[email protected]>
  • Loading branch information
nierob committed Apr 2, 2019
1 parent b5f76ee commit b91e6f6
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/corelib/tools/qscopeguard.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ template <typename F> class QScopeGuard;
template <typename F> QScopeGuard<F> qScopeGuard(F f);

template <typename F>
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
Expand Down Expand Up @@ -86,6 +91,10 @@ class QScopeGuard


template <typename F>
#ifndef __INTEL_COMPILER
// Causes "error #3058: GNU attributes on a template redeclaration have no effect"
Q_REQUIRED_RESULT
#endif
QScopeGuard<F> qScopeGuard(F f)
{
return QScopeGuard<F>(std::move(f));
Expand Down

0 comments on commit b91e6f6

Please sign in to comment.