From 97269ab2949abc0deced5545ff14d41603f46d41 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 19 May 2022 10:35:49 +0200 Subject: [PATCH] QKeySequence: statically assert the sortedness of the MacSpecialKey array This array has, in the past, silently failed this test (cf. 5d8f815e101da3ae9cd6a666cc097853f52b21da). Make sure it doesn't happen again. Change-Id: I26192749d43de4a7add9d14c7ca04391c1799525 Reviewed-by: Giuseppe D'Angelo --- src/gui/kernel/qkeysequence.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/gui/kernel/qkeysequence.cpp b/src/gui/kernel/qkeysequence.cpp index 02f994915f..2507f8720a 100644 --- a/src/gui/kernel/qkeysequence.cpp +++ b/src/gui/kernel/qkeysequence.cpp @@ -18,6 +18,7 @@ #endif #include +#include QT_BEGIN_NAMESPACE @@ -62,6 +63,11 @@ static constexpr MacSpecialKey entries[] = { { Qt::Key_Eject, 0x23CF }, }; +static constexpr bool operator<(const MacSpecialKey &lhs, const MacSpecialKey &rhs) +{ + return lhs.key < rhs.key; +} + static constexpr bool operator<(const MacSpecialKey &lhs, int rhs) { return lhs.key < rhs; @@ -72,6 +78,7 @@ static constexpr bool operator<(int lhs, const MacSpecialKey &rhs) return lhs < rhs.key; } +static_assert(q20::is_sorted(std::begin(entries), std::end(entries))); QChar qt_macSymbolForQtKey(int key) {