QGlobalStatic: fix warning when using cv-qualified types

Says GCC:

    tst_qglobalstatic.cpp: In function ‘{anonymous}::Q_QGS_constInt::Type* {anonymous}::Q_QGS_constInt::innerFunction()’:
    tst_qglobalstatic.cpp:71:51: warning: type qualifiers ignored on cast result type [-Wignored-qualifiers]
       71 | Q_GLOBAL_STATIC_WITH_ARGS(const int, constInt, (42))
          |                                                   ^
    qglobalstatic.h:80:40: note: in definition of macro ‘Q_GLOBAL_STATIC_INTERNAL’
       80 |                 noexcept(noexcept(Type ARGS))
          |                                        ^~~~
    tst_qglobalstatic.cpp:71:1: note: in expansion of macro ‘Q_GLOBAL_STATIC_WITH_ARGS’
       71 | Q_GLOBAL_STATIC_WITH_ARGS(const int, constInt, (42))
          | ^~~~~~~~~~~~~~~~~~~~~~~~~

Fix by a strategic std::remove_cv_t.

Pick-to: 6.2 5.15
Change-Id: If2d81b7965cefdcf3ec115bafb78aabc78d4256c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2021-06-30 13:37:24 +02:00
parent bc1808794d
commit e160cded0a

View File

@ -44,6 +44,8 @@
#include <QtCore/qatomic.h>
#include <type_traits>
QT_BEGIN_NAMESPACE
namespace QtGlobalStatic {
@ -77,7 +79,7 @@ enum GuardValues {
static struct Holder : public HolderBase { \
Type value; \
Holder() \
noexcept(noexcept(Type ARGS)) \
noexcept(noexcept(typename std::remove_cv<Type>::type ARGS)) \
: value ARGS \
{ guard.storeRelaxed(QtGlobalStatic::Initialized); } \
} holder; \