From f946c9fb78e9a267647e9fd1b397d9b7ca2b6664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Nowacki?= Date: Tue, 21 May 2019 15:43:41 +0200 Subject: [PATCH] Fix compilation error on compilers not supporting [[nodiscard]] __warn_unused_result__ and [[nodiscard]] both are masked by Q_REQUIRED_RESULT but there are some minor differences between them. In general [[nodiscard]] is more flexible while __warn_unused_result__ can cause warnings in some contexts, for example: error #2621: attribute "__warn_unused_result__" does not apply here error #3058: GNU attributes on a template redeclaration have no effect That is a fix for regression caused by b91e6f6f40864d54903d707d7f19a9732188b670. Change-Id: Icf11b832f31e714a88536828051f4b7f348cdb36 Reviewed-by: Marc Mutz --- src/corelib/tools/qscopeguard.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/corelib/tools/qscopeguard.h b/src/corelib/tools/qscopeguard.h index d20620e933..45c3f93da4 100644 --- a/src/corelib/tools/qscopeguard.h +++ b/src/corelib/tools/qscopeguard.h @@ -51,8 +51,9 @@ template QScopeGuard qScopeGuard(F f); template class -#ifndef __INTEL_COMPILER -// error #2621: attribute "__warn_unused_result__" does not apply here +#if QT_HAS_CPP_ATTRIBUTE(nodiscard) +// Q_REQUIRED_RESULT can be defined as __warn_unused_result__ or as [[nodiscard]] +// but the 1st one has some limitations for example can be placed only on functions. Q_REQUIRED_RESULT #endif QScopeGuard @@ -90,8 +91,7 @@ private: template -#ifndef __INTEL_COMPILER -// Causes "error #3058: GNU attributes on a template redeclaration have no effect" +#if QT_HAS_CPP_ATTRIBUTE(nodiscard) Q_REQUIRED_RESULT #endif QScopeGuard qScopeGuard(F f)