diff --git a/qpcpp.qm b/qpcpp.qm
index 15182ba0..a8ffbb40 100644
--- a/qpcpp.qm
+++ b/qpcpp.qm
@@ -12039,9 +12039,12 @@ return curr;
//! return with interrupts **disabled**.
- std::uint8_t const prev_prio = (QXK_attr_.prev != nullptr)
+ #ifdef Q_SPY
+std::uint8_t const prev_prio = (QXK_attr_.prev != nullptr)
? QXK_attr_.prev->m_prio
: 0U;
+#endif // Q_SPY
+
std::uint8_t const next_prio = (next != nullptr)
? next->m_prio
: QXK_attr_.actPrio;
diff --git a/src/qxk/qxk.cpp b/src/qxk/qxk.cpp
index 210c2526..8f9bf193 100644
--- a/src/qxk/qxk.cpp
+++ b/src/qxk/qxk.cpp
@@ -453,9 +453,12 @@ QP::QActive * QXK_current() noexcept {
//${QXK-extern-C::QXK_contextSw} .............................................
#if defined(Q_SPY) || defined(QXK_ON_CONTEXT_SW)
void QXK_contextSw(QP::QActive * const next) {
+ #ifdef Q_SPY
std::uint8_t const prev_prio = (QXK_attr_.prev != nullptr)
? QXK_attr_.prev->m_prio
: 0U;
+ #endif // Q_SPY
+
std::uint8_t const next_prio = (next != nullptr)
? next->m_prio
: QXK_attr_.actPrio;