qcompilerdetection.h: Introduce Q_CONSTEXPR_DTOR macro for variables
Add this macro to declare constexpr variables that have destructors marked with Q_DECL_CONSTEXPR_DTOR. Declare variables using the new Q_CONSTEXPR_DTOR macro instead of Q_DECL_CONSTEXPR_DTOR in syntax tests. Move the declarations inside the functions as Q_DECL_CONSTEXPR_DTOR could only be used to declare non-local variables. [ChangeLog][QtCore] Introduced Q_CONSTEXPR_DTOR for variables, which resolves to constexpr when __cpp_constexpr >= 201907L, otherwise it resolves to const. Task-number: QTBUG-124462 Change-Id: I06cd99bb956d9af560e92c326a7c82aa4c8852d1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
94f87d6d65
commit
8fa8c574c0
@ -516,6 +516,7 @@
|
|||||||
* https://en.cppreference.com/w/cpp/feature_test
|
* https://en.cppreference.com/w/cpp/feature_test
|
||||||
* Exceptions:
|
* Exceptions:
|
||||||
* Q_DECL_CONSTEXPR_DTOR constexpr in C++20 for explicit destructors __cpp_constexpr >= 201907L
|
* Q_DECL_CONSTEXPR_DTOR constexpr in C++20 for explicit destructors __cpp_constexpr >= 201907L
|
||||||
|
* Q_CONSTEXPR_DTOR constexpr in C++20 for variables __cpp_constexpr >= 201907L otherwise const
|
||||||
* Q_DECL_EQ_DELETE_X(message) = delete("reason"), __cpp_deleted_function >= 202403L
|
* Q_DECL_EQ_DELETE_X(message) = delete("reason"), __cpp_deleted_function >= 202403L
|
||||||
*
|
*
|
||||||
* C++ extensions:
|
* C++ extensions:
|
||||||
@ -1014,6 +1015,14 @@
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef Q_CONSTEXPR_DTOR
|
||||||
|
# if __cpp_constexpr >= 201907L
|
||||||
|
# define Q_CONSTEXPR_DTOR constexpr
|
||||||
|
# else
|
||||||
|
# define Q_CONSTEXPR_DTOR const
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef Q_DECL_EQ_DELETE_X
|
#ifndef Q_DECL_EQ_DELETE_X
|
||||||
# if defined(__cpp_deleted_function) && __cpp_deleted_function >= 202403L
|
# if defined(__cpp_deleted_function) && __cpp_deleted_function >= 202403L
|
||||||
# define Q_DECL_EQ_DELETE_X(reason) = delete(reason)
|
# define Q_DECL_EQ_DELETE_X(reason) = delete(reason)
|
||||||
|
@ -300,6 +300,23 @@
|
|||||||
|
|
||||||
Use this macro to declare a destructor that can be computed at
|
Use this macro to declare a destructor that can be computed at
|
||||||
compile-time in C++20 or later.
|
compile-time in C++20 or later.
|
||||||
|
|
||||||
|
\sa Q_CONSTEXPR_DTOR
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\macro Q_CONSTEXPR_DTOR
|
||||||
|
\relates <QtCompilerDetection>
|
||||||
|
\since 6.9
|
||||||
|
|
||||||
|
Expands to \c{constexpr} on compilers that support C++20, where
|
||||||
|
\c{__cpp_constexpr} has a value greater than or equal to \c{201907L}.
|
||||||
|
Otherwise, it expands to \c{const}.
|
||||||
|
|
||||||
|
Use this macro to declare a variable that can be constructed at compile-time
|
||||||
|
in C++20 or later.
|
||||||
|
|
||||||
|
\sa Q_DECL_CONSTEXPR_DTOR
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -1004,10 +1004,9 @@ private:
|
|||||||
int *m_arr;
|
int *m_arr;
|
||||||
};
|
};
|
||||||
|
|
||||||
[[maybe_unused]] Q_DECL_CONSTEXPR_DTOR DestructorTest dt(nullptr);
|
|
||||||
|
|
||||||
void tst_QGlobal::CXX20_constexpr_dtor()
|
void tst_QGlobal::CXX20_constexpr_dtor()
|
||||||
{
|
{
|
||||||
|
[[maybe_unused]] Q_CONSTEXPR_DTOR DestructorTest tmp0(nullptr);
|
||||||
#if __cpp_constexpr >= 201907L
|
#if __cpp_constexpr >= 201907L
|
||||||
[[maybe_unused]] constexpr DestructorTest tmp(nullptr);
|
[[maybe_unused]] constexpr DestructorTest tmp(nullptr);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user