Long live Q_UNREACHABLE_RETURN()!

This is a combination of Q_UNREACHABLE() with a return statement.

ATM, the return statement is unconditionally included. If we notice
that some compilers warn about return after __builtin_unreachable(),
then we can map Q_UNREACHABLE_RETURN(...) to Q_UNREACHABLE() without
having to touch all the code that uses explicit Q_UNREACHABLE() +
return.

The fact that Boost has BOOST_UNREACHABLE_RETURN() indicates that
there are compilers that complain about a lack of return after
Q_UNREACHABLE (we know that MSVC, ICC, and GHS are among them), as
well as compilers that complained about a return being present
(Coverity). Take this opportunity to properly adapt to Coverity, by
leaving out the return statement on this compiler.

Apply the macro around the code base, using a clang-tidy transformer
rule:

    const std::string unr = "unr", val = "val", ret = "ret";
    auto makeUnreachableReturn = cat("Q_UNREACHABLE_RETURN(",
                                    ifBound(val, cat(node(val)), cat("")),
                                    ")");
    auto ignoringSwitchCases = [](auto stmt) {
        return anyOf(stmt, switchCase(subStmt(stmt)));
    };

    makeRule(
       stmt(ignoringSwitchCases(stmt(isExpandedFromMacro("Q_UNREACHABLE")).bind(unr)),
            nextStmt(returnStmt(optionally(hasReturnValue(expr().bind(val)))).bind(ret))),
       {changeTo(node(unr), cat(makeUnreachableReturn,
                                ";")),  // TODO: why is the ; lost w/o this?
        changeTo(node(ret), cat(""))},
       cat("use ", makeUnreachableReturn))
    );

where nextStmt() is copied from some upstream clang-tidy check's
private implementation and subStmt() is a private matcher that gives
access to SwitchCase's SubStmt.

A.k.a. qt-use-unreachable-return.

There were some false positives, suppressed them with NOLINTNEXTLINE.

They're not really false positiives, it's just that Clang sees the
world in one way and if conditonal compilation (#if) differs for other
compilers, Clang doesn't know better. This is an artifact of matching
two consecutive statements.

I haven't figured out how to remove the empty line left by the
deletion of the return statement, if it, indeed, was on a separate
line, so post-processed the patch to remove all the lines matching
^\+ *$ from the diff:

  git commit -am meep
  git reset --hard HEAD^
  git diff HEAD..HEAD@{1} | sed '/^\+ *$/d' | recountdiff - | patch -p1

[ChangeLog][QtCore][QtAssert] Added Q_UNREACHABLE_RETURN() macro.

Change-Id: I9782939f16091c964f25b7826e1c0dbd13a71305
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2022-09-22 11:39:44 +02:00
parent 16dbbc8f8c
commit fc76767692
55 changed files with 154 additions and 221 deletions

View File

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

View File

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

View File

@ -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");\

View File

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

View File

@ -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()
*/
/*!

View File

@ -1903,8 +1903,7 @@ void QProcess::setProcessState(ProcessState state)
*/
auto QProcess::setupChildProcess() -> Use_setChildProcessModifier_Instead
{
Q_UNREACHABLE();
return {};
Q_UNREACHABLE_RETURN({});
}
#endif

View File

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

View File

@ -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);
}
}

View File

@ -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(); },

View File

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

View File

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

View File

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

View File

@ -576,8 +576,7 @@ QVariant QCborValue::toVariant() const
if (isSimpleType())
return QVariant::fromValue(toSimpleType());
Q_UNREACHABLE();
return QVariant();
Q_UNREACHABLE_RETURN(QVariant());
}
/*!

View File

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

View File

@ -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());
}
/*!

View File

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

View File

@ -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());
}
/*!

View File

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

View File

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

View File

@ -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);
}
/*!

View File

@ -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);
}
/*

View File

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

View File

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

View File

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

View File

@ -1033,8 +1033,7 @@ static inline uint qUnpremultiplyRgb30(uint rgb30)
case 3:
return rgb30;
}
Q_UNREACHABLE();
return 0;
Q_UNREACHABLE_RETURN(0);
}
template<bool rgbswap>

View File

@ -313,8 +313,7 @@ bool QShortcutMap::tryShortcut(QKeyEvent *e)
return identicalMatches > 0;
}
}
Q_UNREACHABLE();
return false;
Q_UNREACHABLE_RETURN(false);
}
/*! \internal

View File

@ -50,8 +50,7 @@ constexpr int half_point = 1 << 15;
template <QPixelLayout::BPP bpp> static
inline uint QT_FASTCALL fetch1Pixel(const uchar *, int)
{
Q_UNREACHABLE();
return 0;
Q_UNREACHABLE_RETURN(0);
}
template <>
@ -4917,8 +4916,7 @@ void qBlendTexture(int count, const QSpan *spans, void *userData)
ProcessSpans proc;
switch (data->rasterBuffer->format) {
case QImage::Format_Invalid:
Q_UNREACHABLE();
return;
Q_UNREACHABLE_RETURN();
case QImage::Format_ARGB32_Premultiplied:
proc = processTextureSpansARGB32PM[blendType];
break;

View File

@ -212,8 +212,7 @@ inline void QT_FASTCALL storePixel<QPixelLayout::BPP24>(uchar *dest, int index,
template <QPixelLayout::BPP bpp> static
inline uint QT_FASTCALL fetchPixel(const uchar *, int)
{
Q_UNREACHABLE();
return 0;
Q_UNREACHABLE_RETURN(0);
}
template <>

View File

@ -346,8 +346,7 @@ static QList<QGradientStop> qt_preset_gradient_stops(QGradient::Preset preset)
case QGradient::NumPresets:
Q_UNREACHABLE();
}
Q_UNREACHABLE();
return {};
Q_UNREACHABLE_RETURN({});
}
static constexpr QGradient::QGradientData qt_preset_gradient_data[] = {

View File

@ -1435,8 +1435,7 @@ QRhiVertexInputAttribute::Format QRhiImplementation::shaderDescVariableFormatToV
return QRhiVertexInputAttribute::UInt;
default:
Q_UNREACHABLE();
return QRhiVertexInputAttribute::Float;
Q_UNREACHABLE_RETURN(QRhiVertexInputAttribute::Float);
}
}
@ -1478,8 +1477,7 @@ quint32 QRhiImplementation::byteSizePerVertexForVertexInputFormat(QRhiVertexInpu
return sizeof(qint32);
default:
Q_UNREACHABLE();
return 1;
Q_UNREACHABLE_RETURN(1);
}
}
@ -4120,8 +4118,7 @@ bool operator==(const QRhiShaderResourceBinding &a, const QRhiShaderResourceBind
}
break;
default:
Q_UNREACHABLE();
return false;
Q_UNREACHABLE_RETURN(false);
}
return true;
@ -5100,8 +5097,7 @@ static const char *resourceTypeStr(QRhiResource *res)
return "CommandBuffer";
}
Q_UNREACHABLE();
return "";
Q_UNREACHABLE_RETURN("");
}
QRhiImplementation::~QRhiImplementation()
@ -5629,8 +5625,7 @@ const char *QRhi::backendName(Implementation impl)
return "Metal";
}
Q_UNREACHABLE();
return "Unknown";
Q_UNREACHABLE_RETURN("Unknown");
}
/*!
@ -5691,8 +5686,7 @@ static inline const char *deviceTypeStr(QRhiDriverInfo::DeviceType type)
return "Cpu";
}
Q_UNREACHABLE();
return nullptr;
Q_UNREACHABLE_RETURN(nullptr);
}
QDebug operator<<(QDebug dbg, const QRhiDriverInfo &info)
{
@ -7768,8 +7762,7 @@ QRhiPassResourceTracker::BufferStage QRhiPassResourceTracker::toPassTrackerBuffe
if (stages.testFlag(QRhiShaderResourceBinding::GeometryStage))
return QRhiPassResourceTracker::BufGeometryStage;
Q_UNREACHABLE();
return QRhiPassResourceTracker::BufVertexStage;
Q_UNREACHABLE_RETURN(QRhiPassResourceTracker::BufVertexStage);
}
QRhiPassResourceTracker::TextureStage QRhiPassResourceTracker::toPassTrackerTextureStage(QRhiShaderResourceBinding::StageFlags stages)
@ -7788,8 +7781,7 @@ QRhiPassResourceTracker::TextureStage QRhiPassResourceTracker::toPassTrackerText
if (stages.testFlag(QRhiShaderResourceBinding::GeometryStage))
return QRhiPassResourceTracker::TexGeometryStage;
Q_UNREACHABLE();
return QRhiPassResourceTracker::TexVertexStage;
Q_UNREACHABLE_RETURN(QRhiPassResourceTracker::TexVertexStage);
}
QT_END_NAMESPACE

View File

@ -1232,8 +1232,7 @@ bool QRhiGles2::isFeatureSupported(QRhi::Feature feature) const
case QRhi::NonFillPolygonMode:
return !caps.gles;
default:
Q_UNREACHABLE();
return false;
Q_UNREACHABLE_RETURN(false);
}
}
@ -1271,8 +1270,7 @@ int QRhiGles2::resourceLimit(QRhi::ResourceLimit limit) const
case QRhi::MaxVertexOutputs:
return caps.maxVertexOutputs;
default:
Q_UNREACHABLE();
return 0;
Q_UNREACHABLE_RETURN(0);
}
}
@ -2356,8 +2354,7 @@ static inline GLenum toGlTopology(QRhiGraphicsPipeline::Topology t)
case QRhiGraphicsPipeline::Patches:
return GL_PATCHES;
default:
Q_UNREACHABLE();
return GL_TRIANGLES;
Q_UNREACHABLE_RETURN(GL_TRIANGLES);
}
}
@ -2369,8 +2366,7 @@ static inline GLenum toGlCullMode(QRhiGraphicsPipeline::CullMode c)
case QRhiGraphicsPipeline::Back:
return GL_BACK;
default:
Q_UNREACHABLE();
return GL_BACK;
Q_UNREACHABLE_RETURN(GL_BACK);
}
}
@ -2382,8 +2378,7 @@ static inline GLenum toGlFrontFace(QRhiGraphicsPipeline::FrontFace f)
case QRhiGraphicsPipeline::CW:
return GL_CW;
default:
Q_UNREACHABLE();
return GL_CCW;
Q_UNREACHABLE_RETURN(GL_CCW);
}
}
@ -2427,8 +2422,7 @@ static inline GLenum toGlBlendFactor(QRhiGraphicsPipeline::BlendFactor f)
qWarning("Unsupported blend factor %d", f);
return GL_ZERO;
default:
Q_UNREACHABLE();
return GL_ZERO;
Q_UNREACHABLE_RETURN(GL_ZERO);
}
}
@ -2446,8 +2440,7 @@ static inline GLenum toGlBlendOp(QRhiGraphicsPipeline::BlendOp op)
case QRhiGraphicsPipeline::Max:
return GL_MAX;
default:
Q_UNREACHABLE();
return GL_FUNC_ADD;
Q_UNREACHABLE_RETURN(GL_FUNC_ADD);
}
}
@ -2471,8 +2464,7 @@ static inline GLenum toGlCompareOp(QRhiGraphicsPipeline::CompareOp op)
case QRhiGraphicsPipeline::Always:
return GL_ALWAYS;
default:
Q_UNREACHABLE();
return GL_ALWAYS;
Q_UNREACHABLE_RETURN(GL_ALWAYS);
}
}
@ -2496,8 +2488,7 @@ static inline GLenum toGlStencilOp(QRhiGraphicsPipeline::StencilOp op)
case QRhiGraphicsPipeline::DecrementAndWrap:
return GL_DECR_WRAP;
default:
Q_UNREACHABLE();
return GL_KEEP;
Q_UNREACHABLE_RETURN(GL_KEEP);
}
}
@ -2509,8 +2500,7 @@ static inline GLenum toGlPolygonMode(QRhiGraphicsPipeline::PolygonMode mode)
case QRhiGraphicsPipeline::PolygonMode::Line:
return GL_LINE;
default:
Q_UNREACHABLE();
return GL_FILL;
Q_UNREACHABLE_RETURN(GL_FILL);
}
}
@ -2528,8 +2518,7 @@ static inline GLenum toGlMinFilter(QRhiSampler::Filter f, QRhiSampler::Filter m)
else
return m == QRhiSampler::Nearest ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR_MIPMAP_LINEAR;
default:
Q_UNREACHABLE();
return GL_LINEAR;
Q_UNREACHABLE_RETURN(GL_LINEAR);
}
}
@ -2541,8 +2530,7 @@ static inline GLenum toGlMagFilter(QRhiSampler::Filter f)
case QRhiSampler::Linear:
return GL_LINEAR;
default:
Q_UNREACHABLE();
return GL_LINEAR;
Q_UNREACHABLE_RETURN(GL_LINEAR);
}
}
@ -2556,8 +2544,7 @@ static inline GLenum toGlWrapMode(QRhiSampler::AddressMode m)
case QRhiSampler::Mirror:
return GL_MIRRORED_REPEAT;
default:
Q_UNREACHABLE();
return GL_CLAMP_TO_EDGE;
Q_UNREACHABLE_RETURN(GL_CLAMP_TO_EDGE);
}
}
@ -2581,8 +2568,7 @@ static inline GLenum toGlTextureCompareFunc(QRhiSampler::CompareOp op)
case QRhiSampler::Always:
return GL_ALWAYS;
default:
Q_UNREACHABLE();
return GL_NEVER;
Q_UNREACHABLE_RETURN(GL_NEVER);
}
}
@ -4275,8 +4261,7 @@ static inline GLenum toGlShaderType(QRhiShaderStage::Type type)
case QRhiShaderStage::Compute:
return GL_COMPUTE_SHADER;
default:
Q_UNREACHABLE();
return GL_VERTEX_SHADER;
Q_UNREACHABLE_RETURN(GL_VERTEX_SHADER);
}
}
@ -4558,8 +4543,7 @@ static inline QShader::Stage toShaderStage(QRhiShaderStage::Type type)
case QRhiShaderStage::Compute:
return QShader::ComputeStage;
default:
Q_UNREACHABLE();
return QShader::VertexStage;
Q_UNREACHABLE_RETURN(QShader::VertexStage);
}
}
@ -5526,8 +5510,7 @@ bool QGles2GraphicsPipeline::create()
default:
break;
}
Q_UNREACHABLE();
return VtxIdx;
Q_UNREACHABLE_RETURN(VtxIdx);
};
QShaderDescription desc[LastIdx];
QShader::SeparateToCombinedImageSamplerMappingList samplerMappingList[LastIdx];

View File

@ -135,8 +135,7 @@ int QRhiNull::resourceLimit(QRhi::ResourceLimit limit) const
return 32;
}
Q_UNREACHABLE();
return 0;
Q_UNREACHABLE_RETURN(0);
}
const QRhiNativeHandles *QRhiNull::nativeHandles()

View File

@ -1016,8 +1016,7 @@ static inline VkFormat toVkTextureFormat(QRhiTexture::Format format, QRhiTexture
return srgb ? VK_FORMAT_ASTC_12x12_SRGB_BLOCK : VK_FORMAT_ASTC_12x12_UNORM_BLOCK;
default:
Q_UNREACHABLE();
return VK_FORMAT_R8G8B8A8_UNORM;
Q_UNREACHABLE_RETURN(VK_FORMAT_R8G8B8A8_UNORM);
}
}
@ -3813,8 +3812,7 @@ VkSampleCountFlagBits QRhiVulkan::effectiveSampleCount(int sampleCount)
return qvk_sampleCount.mask;
}
Q_UNREACHABLE();
return VK_SAMPLE_COUNT_1_BIT;
Q_UNREACHABLE_RETURN(VK_SAMPLE_COUNT_1_BIT);
}
void QRhiVulkan::enqueueTransitionPassResources(QVkCommandBuffer *cbD)
@ -4336,8 +4334,7 @@ bool QRhiVulkan::isFeatureSupported(QRhi::Feature feature) const
case QRhi::NonFillPolygonMode:
return caps.nonFillPolygonMode;
default:
Q_UNREACHABLE();
return false;
Q_UNREACHABLE_RETURN(false);
}
}
@ -4375,8 +4372,7 @@ int QRhiVulkan::resourceLimit(QRhi::ResourceLimit limit) const
case QRhi::MaxVertexOutputs:
return physDevProperties.limits.maxVertexOutputComponents / 4;
default:
Q_UNREACHABLE();
return 0;
Q_UNREACHABLE_RETURN(0);
}
}
@ -5258,8 +5254,7 @@ static inline VkFilter toVkFilter(QRhiSampler::Filter f)
case QRhiSampler::Linear:
return VK_FILTER_LINEAR;
default:
Q_UNREACHABLE();
return VK_FILTER_NEAREST;
Q_UNREACHABLE_RETURN(VK_FILTER_NEAREST);
}
}
@ -5273,8 +5268,7 @@ static inline VkSamplerMipmapMode toVkMipmapMode(QRhiSampler::Filter f)
case QRhiSampler::Linear:
return VK_SAMPLER_MIPMAP_MODE_LINEAR;
default:
Q_UNREACHABLE();
return VK_SAMPLER_MIPMAP_MODE_NEAREST;
Q_UNREACHABLE_RETURN(VK_SAMPLER_MIPMAP_MODE_NEAREST);
}
}
@ -5288,8 +5282,7 @@ static inline VkSamplerAddressMode toVkAddressMode(QRhiSampler::AddressMode m)
case QRhiSampler::Mirror:
return VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT;
default:
Q_UNREACHABLE();
return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
Q_UNREACHABLE_RETURN(VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE);
}
}
@ -5309,8 +5302,7 @@ static inline VkShaderStageFlagBits toVkShaderStage(QRhiShaderStage::Type type)
case QRhiShaderStage::Geometry:
return VK_SHADER_STAGE_GEOMETRY_BIT;
default:
Q_UNREACHABLE();
return VK_SHADER_STAGE_VERTEX_BIT;
Q_UNREACHABLE_RETURN(VK_SHADER_STAGE_VERTEX_BIT);
}
}
@ -5348,8 +5340,7 @@ static inline VkFormat toVkAttributeFormat(QRhiVertexInputAttribute::Format form
case QRhiVertexInputAttribute::SInt:
return VK_FORMAT_R32_SINT;
default:
Q_UNREACHABLE();
return VK_FORMAT_R32G32B32A32_SFLOAT;
Q_UNREACHABLE_RETURN(VK_FORMAT_R32G32B32A32_SFLOAT);
}
}
@ -5371,8 +5362,7 @@ static inline VkPrimitiveTopology toVkTopology(QRhiGraphicsPipeline::Topology t)
case QRhiGraphicsPipeline::Patches:
return VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
default:
Q_UNREACHABLE();
return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
Q_UNREACHABLE_RETURN(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST);
}
}
@ -5386,8 +5376,7 @@ static inline VkCullModeFlags toVkCullMode(QRhiGraphicsPipeline::CullMode c)
case QRhiGraphicsPipeline::Back:
return VK_CULL_MODE_BACK_BIT;
default:
Q_UNREACHABLE();
return VK_CULL_MODE_NONE;
Q_UNREACHABLE_RETURN(VK_CULL_MODE_NONE);
}
}
@ -5399,8 +5388,7 @@ static inline VkFrontFace toVkFrontFace(QRhiGraphicsPipeline::FrontFace f)
case QRhiGraphicsPipeline::CW:
return VK_FRONT_FACE_CLOCKWISE;
default:
Q_UNREACHABLE();
return VK_FRONT_FACE_COUNTER_CLOCKWISE;
Q_UNREACHABLE_RETURN(VK_FRONT_FACE_COUNTER_CLOCKWISE);
}
}
@ -5460,8 +5448,7 @@ static inline VkBlendFactor toVkBlendFactor(QRhiGraphicsPipeline::BlendFactor f)
case QRhiGraphicsPipeline::OneMinusSrc1Alpha:
return VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA;
default:
Q_UNREACHABLE();
return VK_BLEND_FACTOR_ZERO;
Q_UNREACHABLE_RETURN(VK_BLEND_FACTOR_ZERO);
}
}
@ -5479,8 +5466,7 @@ static inline VkBlendOp toVkBlendOp(QRhiGraphicsPipeline::BlendOp op)
case QRhiGraphicsPipeline::Max:
return VK_BLEND_OP_MAX;
default:
Q_UNREACHABLE();
return VK_BLEND_OP_ADD;
Q_UNREACHABLE_RETURN(VK_BLEND_OP_ADD);
}
}
@ -5504,8 +5490,7 @@ static inline VkCompareOp toVkCompareOp(QRhiGraphicsPipeline::CompareOp op)
case QRhiGraphicsPipeline::Always:
return VK_COMPARE_OP_ALWAYS;
default:
Q_UNREACHABLE();
return VK_COMPARE_OP_ALWAYS;
Q_UNREACHABLE_RETURN(VK_COMPARE_OP_ALWAYS);
}
}
@ -5529,8 +5514,7 @@ static inline VkStencilOp toVkStencilOp(QRhiGraphicsPipeline::StencilOp op)
case QRhiGraphicsPipeline::DecrementAndWrap:
return VK_STENCIL_OP_DECREMENT_AND_WRAP;
default:
Q_UNREACHABLE();
return VK_STENCIL_OP_KEEP;
Q_UNREACHABLE_RETURN(VK_STENCIL_OP_KEEP);
}
}
@ -5542,8 +5526,7 @@ static inline VkPolygonMode toVkPolygonMode(QRhiGraphicsPipeline::PolygonMode mo
case QRhiGraphicsPipeline::Line:
return VK_POLYGON_MODE_LINE;
default:
Q_UNREACHABLE();
return VK_POLYGON_MODE_FILL;
Q_UNREACHABLE_RETURN(VK_POLYGON_MODE_FILL);
}
}
@ -5582,8 +5565,7 @@ static inline VkDescriptorType toVkDescriptorType(const QRhiShaderResourceBindin
return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
default:
Q_UNREACHABLE();
return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Q_UNREACHABLE_RETURN(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
}
}
@ -5625,8 +5607,7 @@ static inline VkCompareOp toVkTextureCompareOp(QRhiSampler::CompareOp op)
case QRhiSampler::Always:
return VK_COMPARE_OP_ALWAYS;
default:
Q_UNREACHABLE();
return VK_COMPARE_OP_NEVER;
Q_UNREACHABLE_RETURN(VK_COMPARE_OP_NEVER);
}
}

View File

@ -1209,8 +1209,7 @@ static inline QTextFormat::Property borderPropertyForEdge(QCss::Edge edge)
case QCss::RightEdge:
return QTextFormat::TableCellRightBorder;
default:
Q_UNREACHABLE();
return QTextFormat::UserProperty;
Q_UNREACHABLE_RETURN(QTextFormat::UserProperty);
}
}
@ -1226,8 +1225,7 @@ static inline QTextFormat::Property borderStylePropertyForEdge(QCss::Edge edge)
case QCss::RightEdge:
return QTextFormat::TableCellRightBorderStyle;
default:
Q_UNREACHABLE();
return QTextFormat::UserProperty;
Q_UNREACHABLE_RETURN(QTextFormat::UserProperty);
}
}
@ -1243,8 +1241,7 @@ static inline QCss::Edge adjacentEdge(QCss::Edge edge)
case QCss::LeftEdge:
return QCss::RightEdge;
default:
Q_UNREACHABLE();
return QCss::NumEdges;
Q_UNREACHABLE_RETURN(QCss::NumEdges);
}
}
@ -1323,8 +1320,7 @@ static inline bool sharesAxis(const QTextTableCell &cell, QCss::Edge edge,
return cell.column() + cell.columnSpan() ==
competingCell.column() + (competingCellEdge == QCss::LeftEdge ? 0 : competingCell.columnSpan());
default:
Q_UNREACHABLE();
return false;
Q_UNREACHABLE_RETURN(false);
}
}

View File

@ -1395,8 +1395,7 @@ void QTextEngine::shapeText(int item) const
}
if (Q_UNLIKELY(!ensureSpace(itemLength))) {
Q_UNREACHABLE(); // ### report OOM error somehow
return;
Q_UNREACHABLE_RETURN(); // ### report OOM error somehow
}
QFontEngine *fontEngine = this->fontEngine(si, &si.ascent, &si.descent, &si.leading);

View File

@ -346,8 +346,7 @@ quint32 FieldLookupTable::indexOfChunk(const Chunk *chunk) const
return quint32(i);
}
Q_UNREACHABLE();
return 0;
Q_UNREACHABLE_RETURN(0);
}
quint32 FieldLookupTable::keyToIndex(const SearchEntry &key) const

View File

@ -241,8 +241,7 @@ QString QSslDiffieHellmanParameters::errorString() const noexcept
return QCoreApplication::translate("QSslDiffieHellmanParameter", "The given Diffie-Hellman parameters are deemed unsafe");
}
Q_UNREACHABLE();
return QString();
Q_UNREACHABLE_RETURN(QString());
}
/*!

View File

@ -1382,8 +1382,7 @@ QByteArray TlsKey::pemHeader() const
else if (algorithm() == QSsl::Dh)
return QByteArrayLiteral("-----BEGIN PRIVATE KEY-----");
Q_UNREACHABLE();
return {};
Q_UNREACHABLE_RETURN({});
}
/*!
@ -1404,8 +1403,7 @@ QByteArray TlsKey::pemFooter() const
else if (algorithm() == QSsl::Dh)
return QByteArrayLiteral("-----END PRIVATE KEY-----");
Q_UNREACHABLE();
return {};
Q_UNREACHABLE_RETURN({});
}
/*!

View File

@ -1414,8 +1414,7 @@ static QImage qt_gl_read_framebuffer(const QSize &size, GLenum internal_format,
return qt_gl_read_framebuffer_rgba8(size, include_alpha, ctx).mirrored(false, flip);
}
Q_UNREACHABLE();
return QImage();
Q_UNREACHABLE_RETURN(QImage());
}
Q_OPENGL_EXPORT QImage qt_gl_read_framebuffer(const QSize &size, bool alpha_format, bool include_alpha)

View File

@ -431,8 +431,7 @@ static bool isSizedTextureFormat(QOpenGLTexture::TextureFormat internalFormat)
return false;
}
Q_UNREACHABLE();
return false;
Q_UNREACHABLE_RETURN(false);
}
static bool isTextureTargetMultisample(QOpenGLTexture::Target target)
@ -456,8 +455,7 @@ static bool isTextureTargetMultisample(QOpenGLTexture::Target target)
return false;
}
Q_UNREACHABLE();
return false;
Q_UNREACHABLE_RETURN(false);
}
bool QOpenGLTexturePrivate::isUsingImmutableStorage() const
@ -756,8 +754,7 @@ static QOpenGLTexture::PixelFormat pixelFormatCompatibleWithInternalFormat(QOpen
return QOpenGLTexture::LuminanceAlpha;
}
Q_UNREACHABLE();
return QOpenGLTexture::NoSourceFormat;
Q_UNREACHABLE_RETURN(QOpenGLTexture::NoSourceFormat);
}
static QOpenGLTexture::PixelType pixelTypeCompatibleWithInternalFormat(QOpenGLTexture::TextureFormat internalFormat)
@ -936,8 +933,7 @@ static QOpenGLTexture::PixelType pixelTypeCompatibleWithInternalFormat(QOpenGLTe
return QOpenGLTexture::UInt8;
}
Q_UNREACHABLE();
return QOpenGLTexture::NoPixelType;
Q_UNREACHABLE_RETURN(QOpenGLTexture::NoPixelType);
}
static bool isCompressedFormat(QOpenGLTexture::TextureFormat internalFormat)
@ -1080,8 +1076,7 @@ static bool isCompressedFormat(QOpenGLTexture::TextureFormat internalFormat)
return false;
}
Q_UNREACHABLE();
return false;
Q_UNREACHABLE_RETURN(false);
}
void QOpenGLTexturePrivate::allocateMutableStorage(QOpenGLTexture::PixelFormat pixelFormat, QOpenGLTexture::PixelType pixelType)

View File

@ -94,8 +94,7 @@ bool isMeteredFromNMMetered(QNetworkManagerInterface::NMMetered metered)
case QNetworkManagerInterface::NM_METERED_UNKNOWN:
return false;
}
Q_UNREACHABLE();
return false;
Q_UNREACHABLE_RETURN(false);
}
} // unnamed namespace

View File

@ -108,8 +108,7 @@ bool QComposeInputContext::filterEvent(const QEvent *event)
case XKB_COMPOSE_NOTHING:
return false;
default:
Q_UNREACHABLE();
return false;
Q_UNREACHABLE_RETURN(false);
}
}

View File

@ -125,8 +125,7 @@ void QLinuxFbDevice::close()
void *QLinuxFbDevice::nativeDisplay() const
{
Q_UNREACHABLE();
return nullptr;
Q_UNREACHABLE_RETURN(nullptr);
}
QPlatformScreen *QLinuxFbDevice::createScreen(const QKmsOutput &output)

View File

@ -89,8 +89,7 @@ static inline QString jobHoldToString(const QCUPSSupport::JobHoldUntil jobHold,
case QCUPSSupport::NoHold:
return QString();
}
Q_UNREACHABLE();
return QString();
Q_UNREACHABLE_RETURN(QString());
}
QCUPSSupport::JobHoldUntilWithTime QCUPSSupport::parseJobHoldUntil(const QString &jobHoldUntil)
@ -176,8 +175,7 @@ static inline QString bannerPageToString(const QCUPSSupport::BannerPage bannerPa
case QCUPSSupport::Secret: return QStringLiteral("secret");
case QCUPSSupport::TopSecret: return QStringLiteral("topsecret");
}
Q_UNREACHABLE();
return QString();
Q_UNREACHABLE_RETURN(QString());
}
static inline QCUPSSupport::BannerPage stringToBannerPage(const QString &bannerPage)

View File

@ -351,8 +351,7 @@ void QAbstractTestLogger::addMessage(QtMsgType type, const QMessageLogContext &c
case QtWarningMsg: return QAbstractTestLogger::QWarning;
case QtFatalMsg: return QAbstractTestLogger::QFatal;
}
Q_UNREACHABLE();
return QAbstractTestLogger::QFatal;
Q_UNREACHABLE_RETURN(QAbstractTestLogger::QFatal);
}();
QString formattedMessage = qFormatLogMessage(type, context, message);

View File

@ -62,8 +62,7 @@ namespace QTest {
case QAbstractTestLogger::BlacklistedXFail:
return "BXFAIL ";
}
Q_UNREACHABLE();
return nullptr;
Q_UNREACHABLE_RETURN(nullptr);
}
static const char *benchmarkResult2String()
@ -89,8 +88,7 @@ namespace QTest {
case QAbstractTestLogger::Warn:
return "WARNING";
}
Q_UNREACHABLE();
return nullptr;
Q_UNREACHABLE_RETURN(nullptr);
}
template <typename T>

View File

@ -1230,8 +1230,7 @@ class WatchDog : public QThread
waitCondition.wait(m, expectationChanged);
return true;
}
Q_UNREACHABLE();
return false;
Q_UNREACHABLE_RETURN(false);
}
public:

View File

@ -599,8 +599,7 @@ static const char *macroNameForOp(QTest::ComparisonOperation op)
case ComparisonOperation::GreaterThanOrEqual:
return "QCOMPARE_GE";
}
Q_UNREACHABLE();
return "";
Q_UNREACHABLE_RETURN("");
}
static const char *failureMessageForOp(QTest::ComparisonOperation op)
@ -622,8 +621,7 @@ static const char *failureMessageForOp(QTest::ComparisonOperation op)
case ComparisonOperation::GreaterThanOrEqual:
return "Left value is expected to be greater than or equal to right value, but is not";
}
Q_UNREACHABLE();
return "";
Q_UNREACHABLE_RETURN("");
}
bool QTestResult::reportResult(bool success, qxp::function_ref<const char *()> lhs,

View File

@ -1554,8 +1554,7 @@ static CborError jsonValueToCbor(CborEncoder *parent, const QJsonValue &v)
return cbor_encode_double(parent, d);
}
}
Q_UNREACHABLE();
return CborUnknownError;
Q_UNREACHABLE_RETURN(CborUnknownError);
}
void Generator::generatePluginMetaData()

View File

@ -38,8 +38,7 @@ static const char *candidateSignal(int which)
case NumCandidateSignals:
break;
};
Q_UNREACHABLE();
return nullptr;
Q_UNREACHABLE_RETURN(nullptr);
}
static const char *signalForMember(const char *member)

View File

@ -129,8 +129,7 @@ static const char *changed_signal(int which)
case 6: return SIGNAL(valueChanged(int));
};
static_assert(7 == NFallbackDefaultProperties);
Q_UNREACHABLE();
return nullptr;
Q_UNREACHABLE_RETURN(nullptr);
}
class QWizardDefaultProperty
@ -1350,8 +1349,7 @@ static QString object_name_for_button(QWizard::WizardButton which)
//case QWizard::NButtons:
;
}
Q_UNREACHABLE();
return QString();
Q_UNREACHABLE_RETURN(QString());
}
bool QWizardPrivate::ensureButton(QWizard::WizardButton which) const

View File

@ -3723,8 +3723,7 @@ static Qt::SortOrder flipOrder(Qt::SortOrder order)
case Qt::DescendingOrder:
return Qt::AscendingOrder;
};
Q_UNREACHABLE();
return Qt::AscendingOrder;
Q_UNREACHABLE_RETURN(Qt::AscendingOrder);
};
void QHeaderViewPrivate::flipSortIndicator(int section)

View File

@ -430,8 +430,7 @@ void tst_QtEndian::endianBitfieldUnions()
testBitfieldUnion<qint32_le_bitfield_union, qint32_le_bitfield_member>();
return;
}
Q_UNREACHABLE();
return;
Q_UNREACHABLE_RETURN();
case QSysInfo::BigEndian:
switch (signedness) {
case Unsigned:
@ -441,8 +440,7 @@ void tst_QtEndian::endianBitfieldUnions()
testBitfieldUnion<qint32_be_bitfield_union, qint32_be_bitfield_member>();
return;
}
Q_UNREACHABLE();
return;
Q_UNREACHABLE_RETURN();
}
}

View File

@ -309,8 +309,7 @@ public slots:
break;
}
Q_UNREACHABLE();
return false;
Q_UNREACHABLE_RETURN(false);
}
private:

View File

@ -80,8 +80,7 @@ const char *algoname(int i)
case QCryptographicHash::Blake2s_256:
return "blake2s_256-";
}
Q_UNREACHABLE();
return nullptr;
Q_UNREACHABLE_RETURN(nullptr);
}
tst_QCryptographicHash::tst_QCryptographicHash()