From 58352e7f9aece796b4d95fddc027e817ef640785 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 21 Jun 2023 11:05:09 +0200 Subject: [PATCH] qcompilerdetection.h: move Q_NODISCARD_CTOR def near Q_REQUIRED_RESULT They both check __has_cpp_attribute(nodiscard), so keep them together. Move the fall-back (empty) definition to the block that does the same for all other such macros. Mention that both P1771 ([[nodiscard]] for ctors) and P1301 ([[nodiscard("reason")]]) use the same numerical value. Amends 959800f6de137f6a77c7d5a2741a5bae0638cbd9. Pick-to: 6.6 Change-Id: I0ef913b6076ffa4058220b542303591de6fefde7 Reviewed-by: Ivan Solovev Reviewed-by: Qt CI Bot --- src/corelib/global/qcompilerdetection.h | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index 73145addfca..e733b80a9ba 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -954,6 +954,13 @@ # define Q_REQUIRED_RESULT [[nodiscard]] #endif +#if __has_cpp_attribute(nodiscard) >= 201907L /* used for both P1771 and P1301... */ +// [[nodiscard]] constructor (P1771) +# ifndef Q_NODISCARD_CTOR +# define Q_NODISCARD_CTOR [[nodiscard]] +# endif +#endif + #if __has_cpp_attribute(maybe_unused) # undef Q_DECL_UNUSED # define Q_DECL_UNUSED [[maybe_unused]] @@ -978,15 +985,6 @@ #define Q_DECL_ENUMERATOR_DEPRECATED Q_DECL_DEPRECATED #define Q_DECL_ENUMERATOR_DEPRECATED_X(x) Q_DECL_DEPRECATED_X(x) -// [[nodiscard]] constructor -#ifndef Q_NODISCARD_CTOR -# if __has_cpp_attribute(nodiscard) >= 201907L -# define Q_NODISCARD_CTOR [[nodiscard]] -# else -# define Q_NODISCARD_CTOR -# endif -#endif - /* * Fallback macros to certain compiler features */ @@ -1012,6 +1010,9 @@ #ifndef Q_REQUIRED_RESULT # define Q_REQUIRED_RESULT #endif +#ifndef Q_NODISCARD_CTOR +# define Q_NODISCARD_CTOR +#endif #ifndef Q_DECL_DEPRECATED # define Q_DECL_DEPRECATED #endif