Skip to content

Commit 49b628a

Browse files
committed
fixed some bugs indicated by msvc extra warnings
1 parent 7c5f0e5 commit 49b628a

File tree

13 files changed

+34
-38
lines changed

13 files changed

+34
-38
lines changed

src/array19.lib/array19/DynamicArrayOf.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ template<class T> struct DynamicArrayOf final {
120120
[[nodiscard]] auto move() -> MoveSlice { return MoveSlice{amendBegin(), m_count}; }
121121

122122
void ensureCapacity(Count count) {
123-
if (totalCapacity() < count) growBy(count - totalCapacity());
123+
if (totalCapacity() < count) growBy(static_cast<size_t>(count - totalCapacity()));
124124
}
125125
void ensureUnusedCapacity(Count count) {
126-
if (unusedCapacity() < count) growBy(count - unusedCapacity());
126+
if (unusedCapacity() < count) growBy(static_cast<size_t>(count - unusedCapacity()));
127127
}
128128

129129
void clear() {

src/array19.lib/array19/SliceOf.equals.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ namespace array19 {
88
template<class T> constexpr bool operator==(const SliceOf<T>& a, const SliceOf<T>& b) {
99
if (a.count() != b.count()) return false;
1010
for (size_t i = 0u; i < a.count() && i < b.count(); i++) {
11-
if (!(a[i] == b[i])) return false;
11+
if (a[i] != b[i]) return false;
1212
}
1313
return true;
1414
}
1515

16-
template<class T> constexpr bool operator!=(const SliceOf<T>& a, const SliceOf<T>& b) { return !(a == b); }
17-
1816
} // namespace array19

src/array19.lib/array19/WithIndex.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ template<class C> struct WithIndex {
2828
constexpr auto operator++() -> iterator& { return (++it, ++index, *this); }
2929
};
3030

31-
constexpr WithIndex(C& c) noexcept : c(c) {}
31+
constexpr WithIndex(C& c) noexcept : c(&c) {}
3232

33-
[[nodiscard]] constexpr auto begin() -> iterator { return iterator{adlBegin(c), {}}; }
34-
[[nodiscard]] constexpr auto end() -> It { return adlEnd(c); }
33+
[[nodiscard]] constexpr auto begin() -> iterator { return iterator{adlBegin(*c), {}}; }
34+
[[nodiscard]] constexpr auto end() -> It { return adlEnd(*c); }
3535

3636
private:
37-
C& c;
37+
C* c;
3838
};
3939

4040
template<class C> WithIndex(C&) -> WithIndex<C>;

src/array19.lib/array19/WithIndex.test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ using namespace array19;
55
void constexpr_WithIndex_test() {
66
constexpr auto sum = [] {
77
int a[] = {1, 2, 3};
8-
auto r = 0;
8+
auto r = size_t{};
99
#ifdef _MSC_VER
1010
auto wi = WithIndex{a}; // cl crashes if we inline this && run it as constexpr
1111
for (auto [v, i] : wi) {

src/enum19.lib/enum19/Enum.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ constexpr auto buildMetaEnumFor(
8989
index++,
9090
memberNames[nameIndex++],
9191
((value = members.filled ? members.value : nextValue),
92-
nextValue = value + 1,
92+
nextValue = static_cast<Underlying>(value + 1),
9393
static_cast<Enum>(value)) //
9494
}...} //
9595
};

src/enum19.lib/enum19/visitEnumMemberNames.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ constexpr bool isCppIdentifierChar(char c) {
1616

1717
template<size_t N> constexpr auto extractEnumMemberNames(StringView body) -> Array<StringView, N> {
1818
auto result = Array<StringView, N>{};
19-
auto i = 0;
19+
auto i = 0u;
2020
auto p = body.data;
2121
auto e = body.data + body.count;
2222

src/lookup19.lib/lookup19/OrderedSetOf.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ template<class T, class Less = DefaultLess> struct OrderedSetOf {
5757
[[nodiscard]] operator Slice() const noexcept { return Slice{begin(), m_count}; }
5858

5959
void ensureCapacity(Count count) {
60-
if (totalCapacity() < count) growBy(count - totalCapacity());
60+
if (totalCapacity() < count) growBy(static_cast<size_t>(count - totalCapacity()));
6161
}
6262
void ensureUnusedCapacity(Count count) {
63-
if (unusedCapacity() < count) growBy(count);
63+
if (unusedCapacity() < count) growBy(static_cast<size_t>(count - unusedCapacity()));
6464
}
6565

6666
/// inserts a single value to the set if it is not yet present
@@ -90,7 +90,7 @@ template<class T, class Less = DefaultLess> struct OrderedSetOf {
9090
return true;
9191
}
9292
if (it != end()) {
93-
memmove(it + 1, it, end() - it);
93+
memmove(it + 1, it, static_cast<size_t>(end() - it));
9494
}
9595
*it = v;
9696
m_count++;
@@ -103,7 +103,7 @@ template<class T, class Less = DefaultLess> struct OrderedSetOf {
103103
void remove(ConstIterator cIt) {
104104
auto it = const_cast<Iterator>(cIt);
105105
if (it + 1 != end()) {
106-
memmove(it, it + 1, end() - it - 1);
106+
memmove(it, it + 1, static_cast<size_t>(end() - it - 1));
107107
}
108108
m_count--;
109109
}
@@ -210,15 +210,15 @@ template<class T, class Less = DefaultLess> struct OrderedSetOf {
210210
}
211211

212212
private:
213-
[[nodiscard]] auto grownStorage(int growBy) const -> AmendableSlice {
213+
[[nodiscard]] auto grownStorage(size_t growBy) const -> AmendableSlice {
214214
auto cur = m_capacity;
215215
auto res = (cur << 1) - (cur >> 1) + (cur >> 4); // * 1.563
216216
if (res < 5) res = 5;
217217
if (res < m_capacity + growBy) res = m_capacity + growBy;
218218
auto ptr = Utils::allocate(res);
219219
return AmendableSlice{ptr, res};
220220
}
221-
void growBy(int by) {
221+
void growBy(size_t by) {
222222
auto newStorage = grownStorage(by);
223223
memcpy(newStorage.begin(), m_pointer, m_count);
224224
Utils::deallocate(SliceOf{m_pointer, m_capacity});

src/serialize19.lib/serialize19/Codec.test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct Person {
1919
template<class A> void serialize(A& a, std::string& s) {
2020
auto size = s.size();
2121
serialize(a, size);
22-
if (a.mode == ArchiveMode::Read) {
22+
if constexpr (A::mode == ArchiveMode::Read) {
2323
s.resize(size);
2424
for (auto i = 0U; i < size; i++) serialize(a, s[i]);
2525
}

src/serialize19.lib/serialize19/Endianess.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ template<class T> auto endianFlipFor(T input) -> T {
1818
return input;
1919
else if constexpr (N == 2) {
2020
auto value = *(uint16_t*)&input;
21-
value = (uint16_t)(value << 8) | (value >> 8);
21+
value = static_cast<uint16_t>((value << 8) | (value >> 8));
2222
return *(T*)&value;
2323
}
2424
else if constexpr (N == 4) {

src/serialize19.lib/serialize19/serialize.std_bitset.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace serialize19 {
88

99
template<Archive A, size_t size> void serialize(A& a, std::bitset<size>& bitset) {
10-
if (a.mode == ArchiveMode::Read) {
10+
if constexpr (A::mode == ArchiveMode::Read) {
1111
for (auto i = 0u; i < size;) {
1212
auto chunk = uint8_t{};
1313
serialize(a, chunk);

0 commit comments

Comments
 (0)