summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp13
-rw-r--r--src/corelib/global/qassert.cpp20
-rw-r--r--src/corelib/global/qassert.h8
-rw-r--r--src/corelib/global/qcompilerdetection.h1
-rw-r--r--src/corelib/global/qcompilerdetection.qdoc2
-rw-r--r--src/corelib/io/qprocess.cpp3
-rw-r--r--src/corelib/io/qurl.cpp6
-rw-r--r--src/corelib/kernel/qmetatype.cpp3
-rw-r--r--src/corelib/kernel/qpropertyprivate.h3
-rw-r--r--src/corelib/kernel/qvariant.cpp6
-rw-r--r--src/corelib/serialization/qcborstreamreader.cpp6
-rw-r--r--src/corelib/serialization/qcborstreamwriter.cpp6
-rw-r--r--src/corelib/serialization/qjsoncbor.cpp3
-rw-r--r--src/corelib/serialization/qjsonvalue.cpp3
-rw-r--r--src/corelib/text/qbytearray.cpp6
-rw-r--r--src/corelib/text/qlocale_tools.cpp3
-rw-r--r--src/corelib/text/qstring.cpp3
-rw-r--r--src/corelib/text/qstringalgorithms_p.h3
-rw-r--r--src/corelib/thread/qfutex_p.h2
-rw-r--r--src/corelib/time/qdatetime.cpp6
-rw-r--r--src/corelib/time/qdatetimeparser.cpp6
-rw-r--r--src/corelib/tools/qatomicscopedvaluerollback_p.h1
-rw-r--r--src/corelib/tools/qfreelist_p.h3
-rw-r--r--src/corelib/tools/qhash.cpp1
24 files changed, 68 insertions, 49 deletions
diff --git a/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp b/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp
index 4d6f566bf8..096e36dc72 100644
--- a/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp
@@ -667,6 +667,19 @@ bool readConfiguration(const QFile &file)
}
//! [qunreachable-switch]
+//! [qunreachable-return]
+ switch (shape) {
+ case Rectangle:
+ return rectangle();
+ case Triangle:
+ return triangle();
+ case Circle:
+ return circle();
+ case NumShapes:
+ Q_UNREACHABLE_RETURN(nullptr);
+ }
+//! [qunreachable-return]
+
//! [qt-version-check]
#include <QtGlobal>
diff --git a/src/corelib/global/qassert.cpp b/src/corelib/global/qassert.cpp
index 2e340ebbb2..4165429d4b 100644
--- a/src/corelib/global/qassert.cpp
+++ b/src/corelib/global/qassert.cpp
@@ -195,7 +195,25 @@ void qBadAlloc()
In debug builds the condition is enforced by an assert to facilitate debugging.
- \sa Q_ASSERT(), Q_ASSUME(), qFatal()
+ \note Use the macro Q_UNREACHABLE_RETURN() to insert return statements for
+ compilers that need them, without causing warnings for compilers that
+ complain about its presence.
+
+ \sa Q_ASSERT(), Q_ASSUME(), qFatal(), Q_UNREACHABLE_RETURN()
*/
+/*!
+ \macro void Q_UNREACHABLE_RETURN(...)
+ \relates <QtAssert>
+ \since 6.5
+
+ This is equivalent to
+ \code
+ Q_UNREACHABLE();
+ return __VA_ARGS__;
+ \endcode
+ except it omits the return on compilers that would warn about it.
+
+ \sa Q_UNREACHABLE()
+*/
QT_END_NAMESPACE
diff --git a/src/corelib/global/qassert.h b/src/corelib/global/qassert.h
index c7ee13176a..28c6b6c8fc 100644
--- a/src/corelib/global/qassert.h
+++ b/src/corelib/global/qassert.h
@@ -70,6 +70,14 @@ inline T *q_check_ptr(T *p) { Q_CHECK_PTR(p); return p; }
Q_UNREACHABLE_IMPL();\
} while (false)
+#ifndef Q_UNREACHABLE_RETURN
+# ifdef Q_COMPILER_COMPLAINS_ABOUT_RETURN_AFTER_UNREACHABLE
+# define Q_UNREACHABLE_RETURN(...) Q_UNREACHABLE()
+# else
+# define Q_UNREACHABLE_RETURN(...) do { Q_UNREACHABLE(); return __VA_ARGS__; } while (0)
+# endif
+#endif
+
#define Q_ASSUME(Expr) \
[] (bool valueOfExpression) {\
Q_ASSERT_X(valueOfExpression, "Q_ASSUME()", "Assumption in Q_ASSUME(\"" #Expr "\") was not correct");\
diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h
index 6dd76ce30a..35d0c5816b 100644
--- a/src/corelib/global/qcompilerdetection.h
+++ b/src/corelib/global/qcompilerdetection.h
@@ -49,6 +49,7 @@
#if defined(__COVERITY__)
# define Q_CC_COVERITY
+# define Q_COMPILER_COMPLAINS_ABOUT_RETURN_AFTER_UNREACHABLE
#endif
/* Symantec C++ is now Digital Mars */
diff --git a/src/corelib/global/qcompilerdetection.qdoc b/src/corelib/global/qcompilerdetection.qdoc
index 05a4b89f1d..377323a5eb 100644
--- a/src/corelib/global/qcompilerdetection.qdoc
+++ b/src/corelib/global/qcompilerdetection.qdoc
@@ -180,7 +180,7 @@
This is useful since a missing break statement is often a bug, and some
compilers can be configured to emit warnings when one is not found.
- \sa Q_UNREACHABLE()
+ \sa Q_UNREACHABLE(), Q_UNREACHABLE_RETURN()
*/
/*!
diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp
index c838b665b7..1af592d39d 100644
--- a/src/corelib/io/qprocess.cpp
+++ b/src/corelib/io/qprocess.cpp
@@ -1903,8 +1903,7 @@ void QProcess::setProcessState(ProcessState state)
*/
auto QProcess::setupChildProcess() -> Use_setChildProcessModifier_Instead
{
- Q_UNREACHABLE();
- return {};
+ Q_UNREACHABLE_RETURN({});
}
#endif
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp
index 3cebb68561..591ed7fe87 100644
--- a/src/corelib/io/qurl.cpp
+++ b/src/corelib/io/qurl.cpp
@@ -3495,8 +3495,7 @@ static QString errorMessage(QUrlPrivate::ErrorCode errorCode, const QString &err
case QUrlPrivate::NoError:
Q_ASSERT_X(false, "QUrl::errorString",
"Impossible: QUrl::errorString should have treated this condition");
- Q_UNREACHABLE();
- return QString();
+ Q_UNREACHABLE_RETURN(QString());
case QUrlPrivate::InvalidSchemeError: {
auto msg = "Invalid scheme (character '%1' not permitted)"_L1;
@@ -3554,8 +3553,7 @@ static QString errorMessage(QUrlPrivate::ErrorCode errorCode, const QString &err
}
Q_ASSERT_X(false, "QUrl::errorString", "Cannot happen, unknown error");
- Q_UNREACHABLE();
- return QString();
+ Q_UNREACHABLE_RETURN(QString());
}
static inline void appendComponentIfPresent(QString &msg, bool present, const char *componentName,
diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp
index 5ad7967605..1047c8c0aa 100644
--- a/src/corelib/kernel/qmetatype.cpp
+++ b/src/corelib/kernel/qmetatype.cpp
@@ -2006,8 +2006,7 @@ static bool convertToEnum(QMetaType fromType, const void *from, QMetaType toType
*static_cast<qint64 *>(to) = value;
return true;
default:
- Q_UNREACHABLE();
- return false;
+ Q_UNREACHABLE_RETURN(false);
}
}
diff --git a/src/corelib/kernel/qpropertyprivate.h b/src/corelib/kernel/qpropertyprivate.h
index 966821fa67..4387f0fbeb 100644
--- a/src/corelib/kernel/qpropertyprivate.h
+++ b/src/corelib/kernel/qpropertyprivate.h
@@ -194,8 +194,7 @@ struct BindingFunctionVTable
return true;
} else {
// Our code will never instantiate this
- Q_UNREACHABLE();
- return false;
+ Q_UNREACHABLE_RETURN(false);
}
},
/*destroy*/[](void *f){ static_cast<Callable *>(f)->~Callable(); },
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp
index 5e949487db..3fb80f203e 100644
--- a/src/corelib/kernel/qvariant.cpp
+++ b/src/corelib/kernel/qvariant.cpp
@@ -2261,8 +2261,7 @@ static bool integralEquals(uint promotedType, const QVariant::Private *d1, const
if (promotedType == QMetaType::ULongLong)
return qulonglong(l1) == qulonglong(l2);
- Q_UNREACHABLE();
- return 0;
+ Q_UNREACHABLE_RETURN(0);
}
namespace {
@@ -2306,8 +2305,7 @@ static std::optional<int> integralCompare(uint promotedType, const QVariant::Pri
if (promotedType == QMetaType::ULongLong)
return spaceShip<qulonglong>(l1, l2);
- Q_UNREACHABLE();
- return 0;
+ Q_UNREACHABLE_RETURN(0);
}
static std::optional<int> numericCompare(const QVariant::Private *d1, const QVariant::Private *d2)
diff --git a/src/corelib/serialization/qcborstreamreader.cpp b/src/corelib/serialization/qcborstreamreader.cpp
index 5f6c0feb49..86fb1f0d7e 100644
--- a/src/corelib/serialization/qcborstreamreader.cpp
+++ b/src/corelib/serialization/qcborstreamreader.cpp
@@ -36,13 +36,11 @@ QT_WARNING_POP
static CborError _cbor_value_dup_string(const CborValue *, void **, size_t *, CborValue *)
{
- Q_UNREACHABLE();
- return CborErrorInternalError;
+ Q_UNREACHABLE_RETURN(CborErrorInternalError);
}
[[maybe_unused]] static CborError cbor_value_get_half_float_as_float(const CborValue *, float *)
{
- Q_UNREACHABLE();
- return CborErrorInternalError;
+ Q_UNREACHABLE_RETURN(CborErrorInternalError);
}
// confirm our constants match TinyCBOR's
diff --git a/src/corelib/serialization/qcborstreamwriter.cpp b/src/corelib/serialization/qcborstreamwriter.cpp
index 0e445451bc..a2ddc15161 100644
--- a/src/corelib/serialization/qcborstreamwriter.cpp
+++ b/src/corelib/serialization/qcborstreamwriter.cpp
@@ -29,14 +29,12 @@ QT_WARNING_POP
// but never defined
[[maybe_unused]] static CborError cbor_encoder_close_container_checked(CborEncoder*, const CborEncoder*)
{
- Q_UNREACHABLE();
- return CborErrorInternalError;
+ Q_UNREACHABLE_RETURN(CborErrorInternalError);
}
[[maybe_unused]] static CborError cbor_encode_float_as_half_float(CborEncoder *, float)
{
- Q_UNREACHABLE();
- return CborErrorInternalError;
+ Q_UNREACHABLE_RETURN(CborErrorInternalError);
}
Q_DECLARE_TYPEINFO(CborEncoder, Q_PRIMITIVE_TYPE);
diff --git a/src/corelib/serialization/qjsoncbor.cpp b/src/corelib/serialization/qjsoncbor.cpp
index 67db3d7d6c..ad0e95061c 100644
--- a/src/corelib/serialization/qjsoncbor.cpp
+++ b/src/corelib/serialization/qjsoncbor.cpp
@@ -576,8 +576,7 @@ QVariant QCborValue::toVariant() const
if (isSimpleType())
return QVariant::fromValue(toSimpleType());
- Q_UNREACHABLE();
- return QVariant();
+ Q_UNREACHABLE_RETURN(QVariant());
}
/*!
diff --git a/src/corelib/serialization/qjsonvalue.cpp b/src/corelib/serialization/qjsonvalue.cpp
index 5383addb70..49fc0d85d1 100644
--- a/src/corelib/serialization/qjsonvalue.cpp
+++ b/src/corelib/serialization/qjsonvalue.cpp
@@ -1097,8 +1097,7 @@ size_t qHash(const QJsonValue &value, size_t seed)
case QJsonValue::Undefined:
return seed;
}
- Q_UNREACHABLE();
- return 0;
+ Q_UNREACHABLE_RETURN(0);
}
#if !defined(QT_NO_DEBUG_STREAM) && !defined(QT_JSON_READONLY)
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp
index 33292d9ca2..29728fcf51 100644
--- a/src/corelib/text/qbytearray.cpp
+++ b/src/corelib/text/qbytearray.cpp
@@ -541,8 +541,7 @@ static const char *zlibOpAsString(ZLibOp op)
case ZLibOp::Compression: return "qCompress";
case ZLibOp::Decompression: return "qUncompress";
}
- Q_UNREACHABLE();
- return nullptr;
+ Q_UNREACHABLE_RETURN(nullptr);
}
Q_DECL_COLD_FUNCTION
@@ -2908,8 +2907,7 @@ QByteArray QByteArray::mid(qsizetype pos, qsizetype len) const
case QContainerImplHelper::Subset:
return QByteArray(d.data() + p, l);
}
- Q_UNREACHABLE();
- return QByteArray();
+ Q_UNREACHABLE_RETURN(QByteArray());
}
/*!
diff --git a/src/corelib/text/qlocale_tools.cpp b/src/corelib/text/qlocale_tools.cpp
index ca6f954bed..f3e664ea41 100644
--- a/src/corelib/text/qlocale_tools.cpp
+++ b/src/corelib/text/qlocale_tools.cpp
@@ -570,8 +570,7 @@ QString qulltoa(qulonglong number, int base, const QStringView zero)
number /= base;
}
} else { // zero should always be either a non-surrogate or a surrogate pair:
- Q_UNREACHABLE();
- return QString();
+ Q_UNREACHABLE_RETURN(QString());
}
return QString(reinterpret_cast<QChar *>(p), end - p);
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp
index e77ff3f3d0..394e1d2c89 100644
--- a/src/corelib/text/qstring.cpp
+++ b/src/corelib/text/qstring.cpp
@@ -5025,8 +5025,7 @@ QString QString::mid(qsizetype position, qsizetype n) const
case QContainerImplHelper::Subset:
return QString(constData() + p, l);
}
- Q_UNREACHABLE();
- return QString();
+ Q_UNREACHABLE_RETURN(QString());
}
/*!
diff --git a/src/corelib/text/qstringalgorithms_p.h b/src/corelib/text/qstringalgorithms_p.h
index 513e2b8cbc..0b8118a858 100644
--- a/src/corelib/text/qstringalgorithms_p.h
+++ b/src/corelib/text/qstringalgorithms_p.h
@@ -47,8 +47,7 @@ template <typename StringType> struct QStringAlgorithms
static inline StringType trimmed_helper_inplace(const NakedStringType &, const Char *, const Char *)
{
// can't happen
- Q_UNREACHABLE();
- return StringType();
+ Q_UNREACHABLE_RETURN(StringType());
}
static inline void trimmed_helper_positions(const Char *&begin, const Char *&end)
diff --git a/src/corelib/thread/qfutex_p.h b/src/corelib/thread/qfutex_p.h
index 9363cc02de..48f03f5ed0 100644
--- a/src/corelib/thread/qfutex_p.h
+++ b/src/corelib/thread/qfutex_p.h
@@ -24,7 +24,7 @@ namespace QtDummyFutex {
constexpr inline bool futexAvailable() { return false; }
template <typename Atomic>
inline bool futexWait(Atomic &, typename Atomic::Type, int = 0)
- { Q_UNREACHABLE(); return false; }
+ { Q_UNREACHABLE_RETURN(false); }
template <typename Atomic> inline void futexWakeOne(Atomic &)
{ Q_UNREACHABLE(); }
template <typename Atomic> inline void futexWakeAll(Atomic &)
diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp
index 46a33d55c7..21f252a70d 100644
--- a/src/corelib/time/qdatetime.cpp
+++ b/src/corelib/time/qdatetime.cpp
@@ -2841,8 +2841,7 @@ static inline bool usesSameOffset(const QDateTimeData &a, const QDateTimeData &b
Q_ASSERT(!a.isShort() && !b.isShort());
return a->m_offsetFromUtc == b->m_offsetFromUtc;
}
- Q_UNREACHABLE();
- return false;
+ Q_UNREACHABLE_RETURN(false);
}
// Refresh the LocalTime or TimeZone validity and offset
@@ -3805,8 +3804,7 @@ qint64 QDateTime::toMSecsSinceEpoch() const
#endif
return 0;
}
- Q_UNREACHABLE();
- return 0;
+ Q_UNREACHABLE_RETURN(0);
}
/*!
diff --git a/src/corelib/time/qdatetimeparser.cpp b/src/corelib/time/qdatetimeparser.cpp
index a90fb46046..ab784912e5 100644
--- a/src/corelib/time/qdatetimeparser.cpp
+++ b/src/corelib/time/qdatetimeparser.cpp
@@ -1441,8 +1441,7 @@ QDateTimeParser::scanString(const QDateTime &defaultValue, bool fixup) const
// Don't care about date or spec, so pick a safe spec:
return StateNode(QDateTime(date, time, Qt::UTC), state, padding, conflicts);
default:
- Q_UNREACHABLE();
- return StateNode();
+ Q_UNREACHABLE_RETURN(StateNode());
}
}
@@ -2253,8 +2252,7 @@ QString QDateTimeParser::getAmPmText(AmPm ap, Case cs) const
case LowerCase: return raw.toLower();
case NativeCase: return raw;
}
- Q_UNREACHABLE();
- return raw;
+ Q_UNREACHABLE_RETURN(raw);
}
/*
diff --git a/src/corelib/tools/qatomicscopedvaluerollback_p.h b/src/corelib/tools/qatomicscopedvaluerollback_p.h
index a0f088ec45..147156d585 100644
--- a/src/corelib/tools/qatomicscopedvaluerollback_p.h
+++ b/src/corelib/tools/qatomicscopedvaluerollback_p.h
@@ -43,6 +43,7 @@ class [[nodiscard]] QAtomicScopedValueRollback
}
// GCC 8.x does not tread __builtin_unreachable() as constexpr
#if !defined(Q_CC_GNU_ONLY) || (Q_CC_GNU >= 900)
+ // NOLINTNEXTLINE(qt-use-unreachable-return): Triggers on Clang, breaking GCC 8
Q_UNREACHABLE();
#endif
return std::memory_order_seq_cst;
diff --git a/src/corelib/tools/qfreelist_p.h b/src/corelib/tools/qfreelist_p.h
index c06c569d23..6bbde5b4b6 100644
--- a/src/corelib/tools/qfreelist_p.h
+++ b/src/corelib/tools/qfreelist_p.h
@@ -124,8 +124,7 @@ class QFreeList
return i;
x -= size;
}
- Q_UNREACHABLE();
- return -1;
+ Q_UNREACHABLE_RETURN(-1);
}
// allocate a block of the given \a size, initialized starting with the given \a offset
diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp
index 9b69c79389..bac2a01afc 100644
--- a/src/corelib/tools/qhash.cpp
+++ b/src/corelib/tools/qhash.cpp
@@ -107,6 +107,7 @@ private:
StateResult result = { 0, OverriddenByEnvironment };
#ifdef QT_BOOTSTRAPPED
Q_UNUSED(which);
+ // NOLINTNEXTLINE(qt-use-unreachable-return): triggers on QT_BOOTSTRAPPED, breaking #else case
Q_UNREACHABLE();
#else
// can't use qEnvironmentVariableIntValue (reentrancy)