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 <ivan.solovev@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2023-06-21 11:05:09 +02:00
parent 70f5d396be
commit 58352e7f9a

View File

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