From f2ddd15d63650eada9b3825dcf5bb7d36a5904a0 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 21 May 2022 16:17:32 -0500 Subject: [PATCH] [ox] Fix compiler warnings --- deps/ox/src/ox/event/signal.hpp | 8 ++++---- deps/ox/src/ox/mc/read.hpp | 2 +- deps/ox/src/ox/std/array.hpp | 2 +- deps/ox/src/ox/std/error.hpp | 2 +- deps/ox/src/ox/std/fmt.hpp | 1 - deps/ox/src/ox/std/hashmap.hpp | 4 ++-- deps/ox/src/ox/std/strops.hpp | 2 +- deps/ox/src/ox/std/vector.hpp | 21 +++++++++++++++++++++ 8 files changed, 31 insertions(+), 11 deletions(-) diff --git a/deps/ox/src/ox/event/signal.hpp b/deps/ox/src/ox/event/signal.hpp index 708c451a..b4adbbff 100644 --- a/deps/ox/src/ox/event/signal.hpp +++ b/deps/ox/src/ox/event/signal.hpp @@ -145,7 +145,7 @@ class Signal { void emit(Args... args) const; - Error emitCheckError(Args... args) noexcept; + Error emitCheckError(Args... args) const noexcept; }; extern template class Signal; @@ -208,7 +208,7 @@ void Signal::emit(Args... args) const { } template -Error Signal::emitCheckError(Args... args) noexcept { +Error Signal::emitCheckError(Args... args) const noexcept { try { for (auto &f : m_slots) { f->call(args...); @@ -321,7 +321,7 @@ class Signal { void emit(Args... args) const noexcept; - Error emitCheckError(Args... args) noexcept; + Error emitCheckError(Args... args) const noexcept; }; extern template class Signal; @@ -396,7 +396,7 @@ void Signal::emit(Args... args) const noexcept { } template -Error Signal::emitCheckError(Args... args) noexcept { +Error Signal::emitCheckError(Args... args) const noexcept { for (auto &f : m_slots) { oxReturnError(f->call(args...)); } diff --git a/deps/ox/src/ox/mc/read.hpp b/deps/ox/src/ox/mc/read.hpp index d1595ac0..8be2b6b0 100644 --- a/deps/ox/src/ox/mc/read.hpp +++ b/deps/ox/src/ox/mc/read.hpp @@ -144,7 +144,7 @@ Error MetalClawReader::field(const char *name, T *val) noexcept { ++m_field; return OxError(0); } else { - if ((m_unionIdx == -1 || m_unionIdx == m_field) && val && m_fieldPresence.get(m_field)) { + if ((m_unionIdx == -1 || m_unionIdx == m_field) && val && m_fieldPresence.get(static_cast(m_field))) { auto reader = child(""); oxReturnError(model(&reader, val)); } diff --git a/deps/ox/src/ox/std/array.hpp b/deps/ox/src/ox/std/array.hpp index de549ffa..61f0eda4 100644 --- a/deps/ox/src/ox/std/array.hpp +++ b/deps/ox/src/ox/std/array.hpp @@ -55,7 +55,7 @@ class Array { } } - constexpr typename std::iterator::difference_type + constexpr typename Iterator::difference_type operator-(const iterator &other) const noexcept { if constexpr(reverse) { return m_offset + other.m_offset; diff --git a/deps/ox/src/ox/std/error.hpp b/deps/ox/src/ox/std/error.hpp index 230069b5..56a1258b 100644 --- a/deps/ox/src/ox/std/error.hpp +++ b/deps/ox/src/ox/std/error.hpp @@ -132,7 +132,7 @@ struct [[nodiscard]] Result { } template - constexpr Result(const Result &other) noexcept: value(other.value), error(error) { + constexpr Result(const Result &other) noexcept: value(other.value), error(other.error) { } constexpr Result(const Error &error) noexcept: error(error) { diff --git a/deps/ox/src/ox/std/fmt.hpp b/deps/ox/src/ox/std/fmt.hpp index 3c3b352d..b3dfbbe6 100644 --- a/deps/ox/src/ox/std/fmt.hpp +++ b/deps/ox/src/ox/std/fmt.hpp @@ -191,7 +191,6 @@ constexpr Result join(auto d, const auto &list) { } T out; out += list.front().value; - const auto dLen = ox_strlen(d); for (auto i = 1ul; i < list.size(); ++i) { out += d; out += list[i]; diff --git a/deps/ox/src/ox/std/hashmap.hpp b/deps/ox/src/ox/std/hashmap.hpp index 2e29097f..00622bc2 100644 --- a/deps/ox/src/ox/std/hashmap.hpp +++ b/deps/ox/src/ox/std/hashmap.hpp @@ -223,8 +223,8 @@ void HashMap::expand() { template uint64_t HashMap::hash(K k, int len) noexcept { uint64_t sum = 1; - for (int i = 0; i < len && k[i]; ++i) { - sum += ((sum + k[i]) * 7) * sum; + for (auto i = 0u; i < static_cast(len) && k[i]; ++i) { + sum += ((sum + static_cast(k[i])) * 7) * sum; } return sum; } diff --git a/deps/ox/src/ox/std/strops.hpp b/deps/ox/src/ox/std/strops.hpp index 298b25b4..d757a776 100644 --- a/deps/ox/src/ox/std/strops.hpp +++ b/deps/ox/src/ox/std/strops.hpp @@ -56,7 +56,7 @@ template [[nodiscard]] constexpr int ox_strcmp(T1 str1, T2 str2) noexcept { auto retval = 0; - auto i = 0; + auto i = 0u; while (str1[i] || str2[i]) { if (str1[i] < str2[i]) { retval = -1; diff --git a/deps/ox/src/ox/std/vector.hpp b/deps/ox/src/ox/std/vector.hpp index a699d1f0..bfc319ff 100644 --- a/deps/ox/src/ox/std/vector.hpp +++ b/deps/ox/src/ox/std/vector.hpp @@ -337,6 +337,8 @@ class Vector: detail::VectorAllocator { [[nodiscard]] constexpr bool contains(const T&) const; + constexpr void insert(std::size_t pos, std::size_t cnt, const T &val); + constexpr void insert(std::size_t pos, const T &val); template @@ -564,6 +566,25 @@ constexpr bool Vector::contains(const T &v) const { return false; } +template +constexpr void Vector::insert(std::size_t pos, std::size_t cnt, const T &val) { + // TODO: insert should ideally have its own expandCap + if (m_size + cnt > m_cap) { + expandCap(m_cap ? m_size + cnt : initialSize); + } + if (pos < m_size) { + for (auto i = m_size + cnt - 1; i > pos; --i) { + std::construct_at(&m_items[i], std::move(m_items[i - cnt])); + } + m_items[pos] = val; + } else { + for (auto i = 0u; i < cnt; ++i) { + std::construct_at(&m_items[pos + i], val); + } + } + ++m_size; +} + template constexpr void Vector::insert(std::size_t pos, const T &val) { // TODO: insert should ideally have its own expandCap