summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qobject.h
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2023-06-22 09:53:23 +0200
committerMarc Mutz <marc.mutz@qt.io>2023-06-22 13:20:26 +0000
commit2b9ef2eb44c084d39ef8324cfe1ae42a98b3038f (patch)
treed212460280257673fdfc0570398332733961dd81 /src/corelib/kernel/qobject.h
parentc33fd574c970eb920a899a9caccb2e6b1838ee19 (diff)
Pacify MSVC compiler incorrectly warning about unused variable
Under some circumstances, MSVC seems to complain about SlotArgumentCount being unused qobject.h(210): warning C4189: 'SlotArgumentCount': local variable is initialized but not referenced note: see reference to function template instantiation 'QMetaObject::Connection QObject::connect<void(__cdecl QAction::* )(bool), main::<lambda_1>>(const QAction *,Func1, const QtPrivate::ContextTypeForFunctor<main::<lambda_1>,void>::ContextType *, Func2 &&,Qt::ConnectionType)' being compiled This is nonsense, as SlotArgumentCount is used in the next line, to construct the list of signal arguments, but the workaround to declare the variable as [[maybe_unused]] is trivial. Add a connect statement to the test case that creates such a connection. This does not produce any warning with or without the attribute (and if it did, the build would fail for CI configuratinos setting -Werror). Pick-to: 6.6 Fixes: QTBUG-114781 Change-Id: I4ee6f7d57c2836ef3dd9741d037d48181af2cdec Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'src/corelib/kernel/qobject.h')
-rw-r--r--src/corelib/kernel/qobject.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/corelib/kernel/qobject.h b/src/corelib/kernel/qobject.h
index 49435b9701..182edaf7f2 100644
--- a/src/corelib/kernel/qobject.h
+++ b/src/corelib/kernel/qobject.h
@@ -207,6 +207,7 @@ public:
"Return type of the slot is not compatible with the return type of the signal.");
} else {
constexpr int FunctorArgumentCount = QtPrivate::ComputeFunctorArgumentCount<std::decay_t<Func2>, typename SignalType::Arguments>::Value;
+ [[maybe_unused]]
constexpr int SlotArgumentCount = (FunctorArgumentCount >= 0) ? FunctorArgumentCount : 0;
typedef typename QtPrivate::FunctorReturnType<std::decay_t<Func2>, typename QtPrivate::List_Left<typename SignalType::Arguments, SlotArgumentCount>::Value>::Value SlotReturnType;