Remove checks for features available in C++17

This patch removes most of the checks that are made using C++20
__cpp_* macros for features available in C++17 and earlier.
Library feature check macros (__cpp_lib_*) are unaffected.

Change-Id: I557b2bd0d4ff09b13837555e9880eb28e0355f64
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Ievgenii Meshcheriakov 2021-09-30 14:12:02 +02:00
parent a1e7c441de
commit 9a3f4afb70
17 changed files with 2 additions and 78 deletions

View File

@ -129,7 +129,6 @@ struct ReduceResultType<R(*)(A...)>
using ResultType = typename std::tuple_element<0, std::tuple<A...>>::type;
};
#if defined(__cpp_noexcept_function_type) && __cpp_noexcept_function_type >= 201510
template <class U, class V>
struct ReduceResultType<void(*)(U&,V) noexcept>
{
@ -141,7 +140,6 @@ struct ReduceResultType<T(C::*)(U) noexcept>
{
using ResultType = C;
};
#endif
template<class T, class Enable = void>
struct hasCallOperator : std::false_type

View File

@ -1114,10 +1114,8 @@
# define Q_DECL_DEPRECATED_X(x) [[deprecated(x)]]
#endif
#if defined(__cpp_enumerator_attributes) && __cpp_enumerator_attributes >= 201411
# define Q_DECL_ENUMERATOR_DEPRECATED Q_DECL_DEPRECATED
# define Q_DECL_ENUMERATOR_DEPRECATED_X(x) Q_DECL_DEPRECATED_X(x)
#endif
#define Q_DECL_ENUMERATOR_DEPRECATED Q_DECL_DEPRECATED
#define Q_DECL_ENUMERATOR_DEPRECATED_X(x) Q_DECL_DEPRECATED_X(x)
/*
* Fallback macros to certain compiler features
@ -1153,12 +1151,6 @@
#ifndef Q_DECL_DEPRECATED_X
# define Q_DECL_DEPRECATED_X(text) Q_DECL_DEPRECATED
#endif
#ifndef Q_DECL_ENUMERATOR_DEPRECATED
# define Q_DECL_ENUMERATOR_DEPRECATED
#endif
#ifndef Q_DECL_ENUMERATOR_DEPRECATED_X
# define Q_DECL_ENUMERATOR_DEPRECATED_X(x)
#endif
#ifndef Q_DECL_EXPORT
# define Q_DECL_EXPORT
#endif

View File

@ -158,7 +158,6 @@ namespace QtPrivate {
(o->*f)((*reinterpret_cast<typename RemoveRef<SignalArgs>::Type *>(arg[II+1]))...), ApplyReturnValue<R>(arg[0]);
}
};
#if defined(__cpp_noexcept_function_type) && __cpp_noexcept_function_type >= 201510
template <int... II, typename... SignalArgs, typename R, typename... SlotArgs, typename SlotRet, class Obj>
struct FunctorCall<IndexesList<II...>, List<SignalArgs...>, R, SlotRet (Obj::*)(SlotArgs...) noexcept> {
static void call(SlotRet (Obj::*f)(SlotArgs...) noexcept, Obj *o, void **arg) {
@ -171,7 +170,6 @@ namespace QtPrivate {
(o->*f)((*reinterpret_cast<typename RemoveRef<SignalArgs>::Type *>(arg[II+1]))...), ApplyReturnValue<R>(arg[0]);
}
};
#endif
template<class Obj, typename Ret, typename... Args> struct FunctionPointer<Ret (Obj::*) (Args...)>
{
@ -210,7 +208,6 @@ namespace QtPrivate {
}
};
#if defined(__cpp_noexcept_function_type) && __cpp_noexcept_function_type >= 201510
template<class Obj, typename Ret, typename... Args> struct FunctionPointer<Ret (Obj::*) (Args...) noexcept>
{
typedef Obj Object;
@ -247,7 +244,6 @@ namespace QtPrivate {
FunctorCall<typename Indexes<ArgumentCount>::Value, SignalArgs, R, Function>::call(f, arg);
}
};
#endif
template<typename Function, int N> struct Functor
{

View File

@ -84,15 +84,11 @@ QT_BEGIN_NAMESPACE
namespace {
template <typename Mutex, typename Lock =
#if defined(__cpp_guaranteed_copy_elision) && __cpp_guaranteed_copy_elision >= 201606L
# if defined(__cpp_lib_scoped_lock) && __cpp_lib_scoped_lock >= 201703L
std::scoped_lock
# else
std::lock_guard
# endif
#else
std::unique_lock
#endif
<typename std::decay<Mutex>::type>
>
Lock qt_scoped_lock(Mutex &mutex)

View File

@ -663,12 +663,10 @@ public:
}
};
#if defined(__cpp_deduction_guides) && __cpp_deduction_guides >= 201606
template <typename InputIterator,
typename ValueType = typename std::iterator_traits<InputIterator>::value_type,
QtPrivate::IfIsInputIterator<InputIterator> = true>
QList(InputIterator, InputIterator) -> QList<ValueType>;
#endif
template <typename T>
inline void QList<T>::resize_internal(qsizetype newSize)

View File

@ -86,9 +86,7 @@ private:
bool m_invoke = true;
};
#ifdef __cpp_deduction_guides
template <typename F> QScopeGuard(F(&)()) -> QScopeGuard<F(*)()>;
#endif
//! [qScopeGuard]
template <typename F>

View File

@ -235,12 +235,10 @@ private:
Hash q_hash;
};
#if defined(__cpp_deduction_guides) && __cpp_deduction_guides >= 201606
template <typename InputIterator,
typename ValueType = typename std::iterator_traits<InputIterator>::value_type,
QtPrivate::IfIsInputIterator<InputIterator> = true>
QSet(InputIterator, InputIterator) -> QSet<ValueType>;
#endif
template <typename T>
size_t qHash(const QSet<T> &key, size_t seed = 0)

View File

@ -386,12 +386,10 @@ private:
}
};
#if defined(__cpp_deduction_guides) && __cpp_deduction_guides >= 201606
template <typename InputIterator,
typename ValueType = typename std::iterator_traits<InputIterator>::value_type,
QtPrivate::IfIsInputIterator<InputIterator> = true>
QVarLengthArray(InputIterator, InputIterator) -> QVarLengthArray<ValueType>;
#endif
template <class T, qsizetype Prealloc>
Q_INLINE_TEMPLATE QVarLengthArray<T, Prealloc>::QVarLengthArray(qsizetype asize)

View File

@ -118,7 +118,6 @@ public:
constexpr quint8 alpha8() const { return div_257(alpha()); }
constexpr uint toArgb32() const
{
#if defined(__cpp_constexpr) && __cpp_constexpr-0 >= 201304
quint64 br = rgba & Q_UINT64_C(0xffff0000ffff);
quint64 ag = (rgba >> 16) & Q_UINT64_C(0xffff0000ffff);
br += Q_UINT64_C(0x8000000080);
@ -135,9 +134,6 @@ public:
| ((br << 16) & 0xff0000)
| (ag & 0xff00)
| ((br >> 32) & 0xff);
#endif
#else
return uint((alpha8() << 24) | (red8() << 16) | (green8() << 8) | blue8());
#endif
}
constexpr ushort toRgb16() const

View File

@ -535,8 +535,6 @@ void tst_QGlobal::testqOverload()
QVERIFY(QConstOverload<QByteArray>::of(&Overloaded::mixedFoo) ==
static_cast<void (Overloaded::*)(QByteArray) const>(&Overloaded::mixedFoo));
#if defined(__cpp_variable_templates) && __cpp_variable_templates >= 201304 // C++14
// void returning free overloaded functions
QVERIFY(qOverload<>(&freeOverloaded) ==
static_cast<void (*)()>(&freeOverloaded));
@ -580,7 +578,6 @@ void tst_QGlobal::testqOverload()
QVERIFY(qConstOverload<QByteArray>(&Overloaded::mixedFoo) ==
static_cast<void (Overloaded::*)(QByteArray) const>(&Overloaded::mixedFoo));
#endif
#endif
}

View File

@ -827,7 +827,6 @@ void tst_QMetaObject::invokePointer()
QCOMPARE(obj.slotResult, QString("sl1:bubu"));
}
QCOMPARE(countedStructObjectsCount, 0);
#ifdef __cpp_init_captures
{
CountedStruct str;
std::unique_ptr<int> ptr( new int );
@ -835,7 +834,6 @@ void tst_QMetaObject::invokePointer()
QCOMPARE(obj.slotResult, QString("sl1:1"));
}
QCOMPARE(countedStructObjectsCount, 0);
#endif
}
void tst_QMetaObject::invokeQueuedMetaMember()
@ -1151,7 +1149,6 @@ void tst_QMetaObject::invokeBlockingQueuedPointer()
QCOMPARE(exp, QString("yessir"));
QCOMPARE(obj.slotResult, QString("sl1:bubu"));
}
#ifdef __cpp_init_captures
{
std::unique_ptr<int> ptr(new int);
QVERIFY(QMetaObject::invokeMethod(&obj,
@ -1159,7 +1156,6 @@ void tst_QMetaObject::invokeBlockingQueuedPointer()
Qt::BlockingQueuedConnection));
QCOMPARE(obj.slotResult, QString("sl1:hehe"));
}
#endif
QVERIFY(QMetaObject::invokeMethod(&obj, [&](){obj.moveToThread(QThread::currentThread());}, Qt::BlockingQueuedConnection));
t.quit();
QVERIFY(t.wait());

View File

@ -1509,7 +1509,6 @@ void tst_QStringApiSymmetry::tok_impl() const
QCOMPARE(toQStringList(tok), resultCS);
}
#ifdef __cpp_deduction_guides
QCOMPARE(toQStringList(QStringTokenizer{haystack, needle}), resultCS);
QCOMPARE(toQStringList(QStringTokenizer{haystack, needle, Qt::KeepEmptyParts, Qt::CaseSensitive}), resultCS);
QCOMPARE(toQStringList(QStringTokenizer{haystack, needle, Qt::CaseInsensitive, Qt::KeepEmptyParts}), resultCIS);
@ -1522,7 +1521,6 @@ void tst_QStringApiSymmetry::tok_impl() const
// yet `tok` should have kept a copy alive as needed:
QCOMPARE(toQStringList(tok), resultCS);
}
#endif // __cpp_deduction_guides
if constexpr (has_tokenize_method_v<Haystack>) {
QCOMPARE(toQStringList(haystack.tokenize(needle)), resultCS);

View File

@ -552,13 +552,11 @@ void tst_QStringView::tokenize() const
QFETCH(const QStringList, result);
// lvalue QString
#ifdef __cpp_deduction_guides
{
auto rit = result.cbegin();
for (auto sv : QStringTokenizer{str, sep})
QCOMPARE(sv, *rit++);
}
#endif
{
auto rit = result.cbegin();
for (auto sv : QStringView{str}.tokenize(sep))
@ -566,13 +564,11 @@ void tst_QStringView::tokenize() const
}
// rvalue QString
#ifdef __cpp_deduction_guides
{
auto rit = result.cbegin();
for (auto sv : QStringTokenizer{str, QString{sep}})
QCOMPARE(sv, *rit++);
}
#endif
{
auto rit = result.cbegin();
for (auto sv : QStringView{str}.tokenize(QString{sep}))
@ -580,13 +576,11 @@ void tst_QStringView::tokenize() const
}
// (rvalue) QChar
#ifdef __cpp_deduction_guides
if (sep.size() == 1) {
auto rit = result.cbegin();
for (auto sv : QStringTokenizer{str, sep.front()})
QCOMPARE(sv, *rit++);
}
#endif
if (sep.size() == 1) {
auto rit = result.cbegin();
for (auto sv : QStringView{str}.tokenize(sep.front()))
@ -594,13 +588,11 @@ void tst_QStringView::tokenize() const
}
// (rvalue) char16_t
#ifdef __cpp_deduction_guides
if (sep.size() == 1) {
auto rit = result.cbegin();
for (auto sv : QStringTokenizer{str, *qToStringViewIgnoringNull(sep).utf16()})
QCOMPARE(sv, *rit++);
}
#endif
if (sep.size() == 1) {
auto rit = result.cbegin();
for (auto sv : QStringView{str}.tokenize(*qToStringViewIgnoringNull(sep).utf16()))
@ -615,20 +607,17 @@ void tst_QStringView::tokenize() const
return literal;
};
const std::unique_ptr<const char16_t[]> literal = make_literal(sep);
#ifdef __cpp_deduction_guides
{
auto rit = result.cbegin();
for (auto sv : QStringTokenizer{str, literal.get()})
QCOMPARE(sv, *rit++);
}
#endif
{
auto rit = result.cbegin();
for (auto sv : QStringView{str}.tokenize(literal.get()))
QCOMPARE(sv, *rit++);
}
#ifdef __cpp_deduction_guides
#ifdef __cpp_lib_ranges
// lvalue QString
{
@ -657,7 +646,6 @@ void tst_QStringView::tokenize() const
QCOMPARE(result, actual);
}
#endif // __cpp_lib_ranges
#endif // __cpp_deduction_guides
}
template <typename Char>

View File

@ -1143,7 +1143,6 @@ void tst_QList::count() const
void tst_QList::cpp17ctad() const
{
#ifdef __cpp_deduction_guides
#define QVERIFY_IS_VECTOR_OF(obj, Type) \
QVERIFY2((std::is_same<decltype(obj), QList<Type>>::value), \
QMetaType::fromType<decltype(obj)::value_type>().name())
@ -1163,9 +1162,6 @@ void tst_QList::cpp17ctad() const
CHECK(QString, QStringLiteral("one"), QStringLiteral("two"), QStringLiteral("three"));
#undef QVERIFY_IS_VECTOR_OF
#undef CHECK
#else
QSKIP("This test requires C++17 Constructor Template Argument Deduction support enabled in the compiler.");
#endif
}
void tst_QList::data() const

View File

@ -94,7 +94,6 @@ static int s_globalState = 0;
void tst_QScopeGuard::construction()
{
#ifdef __cpp_deduction_guides
QScopeGuard fromLambda([] { });
QScopeGuard fromFunction(func);
QScopeGuard fromFunctionPointer(&func);
@ -105,14 +104,10 @@ void tst_QScopeGuard::construction()
std::function<void()> stdFunction(func);
QScopeGuard fromNamedStdFunction(stdFunction);
#endif
#else
QSKIP("This test requires C++17 Class Template Argument Deduction support enabled in the compiler.");
#endif
}
void tst_QScopeGuard::constructionFromLvalue()
{
#ifdef __cpp_deduction_guides
Callable::resetCounts();
{
Callable callable;
@ -127,14 +122,10 @@ void tst_QScopeGuard::constructionFromLvalue()
}
QCOMPARE(Callable::copied, 1);
QCOMPARE(Callable::moved, 0);
#else
QSKIP("This test requires C++17 Class Template Argument Deduction support enabled in the compiler.");
#endif
}
void tst_QScopeGuard::constructionFromRvalue()
{
#ifdef __cpp_deduction_guides
Callable::resetCounts();
{
Callable callable;
@ -149,9 +140,6 @@ void tst_QScopeGuard::constructionFromRvalue()
}
QCOMPARE(Callable::copied, 0);
QCOMPARE(Callable::moved, 1);
#else
QSKIP("This test requires C++17 Class Template Argument Deduction support enabled in the compiler.");
#endif
}
void tst_QScopeGuard::leavingScope()

View File

@ -339,7 +339,6 @@ void tst_QSet::clear()
void tst_QSet::cpp17ctad()
{
#ifdef __cpp_deduction_guides
#define QVERIFY_IS_SET_OF(obj, Type) \
QVERIFY2((std::is_same<decltype(obj), QSet<Type>>::value), \
QMetaType::fromType<decltype(obj)::value_type>().name())
@ -359,9 +358,6 @@ void tst_QSet::cpp17ctad()
CHECK(QString, QStringLiteral("one"), QStringLiteral("two"), QStringLiteral("three"));
#undef QVERIFY_IS_SET_OF
#undef CHECK
#else
QSKIP("This test requires C++17 Constructor Template Argument Deduction support enabled in the compiler.");
#endif
}
void tst_QSet::remove()

View File

@ -907,7 +907,6 @@ void tst_QVarLengthArray::count()
void tst_QVarLengthArray::cpp17ctad()
{
#ifdef __cpp_deduction_guides
#define QVERIFY_IS_VLA_OF(obj, Type) \
QVERIFY2((std::is_same<decltype(obj), QVarLengthArray<Type>>::value), \
QMetaType::fromType<decltype(obj)::value_type>().name())
@ -927,10 +926,6 @@ void tst_QVarLengthArray::cpp17ctad()
CHECK(QString, QStringLiteral("one"), QStringLiteral("two"), QStringLiteral("three"));
#undef QVERIFY_IS_VLA_OF
#undef CHECK
#else
QSKIP("This test requires C++17 Constructor Template Argument Deduction support enabled in the compiler.");
#endif
}
void tst_QVarLengthArray::first()