Skip to content

Commit

Permalink
Fix Clang warnings and errors
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-stahlberg committed Mar 15, 2024
1 parent 010f2de commit 2bbbb52
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 37 deletions.
1 change: 0 additions & 1 deletion include/flatmemory/details/byte_buffer_segmented.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#ifndef FLATMEMORY_BYTE_BUFFER_SEGMENTED_HPP_
#define FLATMEMORY_BYTE_BUFFER_SEGMENTED_HPP_

#include "flatmemory/details/layout_utils.hpp"
#include "flatmemory/details/type_traits.hpp"

#include <cassert>
Expand Down
6 changes: 2 additions & 4 deletions include/flatmemory/details/containers/unordered_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

#include "flatmemory/details/builder.hpp"
#include "flatmemory/details/byte_buffer_segmented.hpp"
#include "flatmemory/details/byte_buffer_utils.hpp"
#include "flatmemory/details/type_traits.hpp"
#include "flatmemory/details/view.hpp"
#include "flatmemory/details/view_const.hpp"

#include <iostream>
#include <unordered_set>

namespace flatmemory
Expand Down Expand Up @@ -42,8 +40,8 @@ class UnorderedSet
// Data to be accessed
std::unordered_set<ConstView<T>, Hash, Equal> m_data;

using iterator = std::unordered_set<ConstView<T>, Hash, Equal>::iterator;
using const_iterator = std::unordered_set<ConstView<T>, Hash, Equal>::const_iterator;
using iterator = typename std::unordered_set<ConstView<T>, Hash, Equal>::iterator;
using const_iterator = typename std::unordered_set<ConstView<T>, Hash, Equal>::const_iterator;

public:
explicit UnorderedSet(NumBytes n = 1000000) : m_storage(ByteBufferSegmented(n)) {}
Expand Down
8 changes: 4 additions & 4 deletions include/flatmemory/details/containers/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class VariableSizedTypeVector
// Data to be accessed
std::vector<View<T>> m_data;

using iterator = std::vector<View<T>>::iterator;
using const_iterator = std::vector<View<T>>::const_iterator;
using iterator = typename std::vector<View<T>>::iterator;
using const_iterator = typename std::vector<View<T>>::const_iterator;

public:
explicit VariableSizedTypeVector(NumBytes n = 1000000) : m_storage(ByteBufferSegmented(n)) {}
Expand Down Expand Up @@ -113,8 +113,8 @@ class FixedSizedTypeVector

const Builder<T> m_default_builder;

using iterator = std::vector<View<T>>::iterator;
using const_iterator = std::vector<View<T>>::const_iterator;
using iterator = typename std::vector<View<T>>::iterator;
using const_iterator = typename std::vector<View<T>>::const_iterator;

public:
FixedSizedTypeVector(Builder<T>&& default_builder, NumBytes n = 1000000) : m_storage(ByteBufferSegmented(n)), m_default_builder(std::move(default_builder))
Expand Down
15 changes: 6 additions & 9 deletions include/flatmemory/details/types/bitset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@
#include <algorithm>
#include <bit>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>

namespace flatmemory
{
Expand Down Expand Up @@ -257,7 +254,7 @@ class Operator<Bitset<Block>>

for (std::size_t index = 0; index < common_size; ++index)
{
if (blocks[index] & other_blocks[index] != other_blocks[index])
if (blocks[index] & (other_blocks[index] != other_blocks[index]))
{
// There exists a set bit in block that is not set in block.
return false;
Expand Down Expand Up @@ -308,7 +305,7 @@ class Operator<Bitset<Block>>

for (std::size_t index = 0; index < common_size; ++index)
{
if (blocks[index] & other_blocks[index] > 0)
if (blocks[index] & (other_blocks[index] > 0))
{
// block and other_block have set bits in common
return false;
Expand Down Expand Up @@ -535,7 +532,7 @@ class View<Bitset<Block>>
{
private:
using BitsetOperator = Operator<Bitset<Block>>;
using const_iterator = BitsetOperator::const_iterator;
using const_iterator = typename BitsetOperator::const_iterator;

uint8_t* m_buf;

Expand Down Expand Up @@ -664,7 +661,7 @@ class ConstView<Bitset<Block>>
{
private:
using BitsetOperator = Operator<Bitset<Block>>;
using const_iterator = BitsetOperator::const_iterator;
using const_iterator = typename BitsetOperator::const_iterator;

const uint8_t* m_buf;

Expand Down Expand Up @@ -754,7 +751,7 @@ class ConstView<Bitset<Block>>
* Getters
*/

[[nodiscard]] uint8_t* buffer() { return m_buf; }
[[nodiscard]] const uint8_t* buffer() const { return m_buf; }

[[nodiscard]] size_t buffer_size() const
{
Expand Down Expand Up @@ -785,7 +782,7 @@ class Builder<Bitset<Block>> : public IBuilder<Builder<Bitset<Block>>>
{
private:
using BitsetOperator = Operator<Bitset<Block>>;
using const_iterator = BitsetOperator::const_iterator;
using const_iterator = typename BitsetOperator::const_iterator;

bool m_default_bit_value;
Builder<Vector<Block>> m_blocks;
Expand Down
7 changes: 1 addition & 6 deletions include/flatmemory/details/types/trivial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,11 @@
#include "flatmemory/details/byte_buffer.hpp"
#include "flatmemory/details/byte_buffer_utils.hpp"
#include "flatmemory/details/layout.hpp"
#include "flatmemory/details/layout_utils.hpp"
#include "flatmemory/details/type_traits.hpp"
#include "flatmemory/details/view.hpp"
#include "flatmemory/details/view_const.hpp"

#include <algorithm>
#include <cassert>
#include <iostream>
#include <string>
#include <tuple>

namespace flatmemory
{
Expand Down Expand Up @@ -183,7 +178,7 @@ class ConstView<Trivial<T>>
return sizeof(T);
}

[[nodiscard]] uint8_t* buffer() { return m_buf; }
[[nodiscard]] const uint8_t* buffer() const { return m_buf; }
};
}

Expand Down
23 changes: 11 additions & 12 deletions include/flatmemory/details/types/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include <algorithm>
#include <cassert>
#include <iostream>
#include <limits>
#include <vector>

namespace flatmemory
Expand Down Expand Up @@ -115,8 +114,8 @@ class Builder<Vector<T>> : public IBuilder<Builder<Vector<T>>>
private:
using T_ = typename maybe_builder<T>::type;

using iterator = std::vector<T_>::iterator;
using const_iterator = std::vector<T_>::const_iterator;
using iterator = typename std::vector<T_>::iterator;
using const_iterator = typename std::vector<T_>::const_iterator;

std::vector<T_> m_data;
ByteBuffer m_buffer;
Expand Down Expand Up @@ -365,7 +364,7 @@ class View<Vector<T>>
class iterator
{
private:
uint8_t* buf;
uint8_t* m_buf;

public:
using difference_type = std::ptrdiff_t;
Expand All @@ -374,15 +373,15 @@ class View<Vector<T>>
using reference = typename maybe_view<T>::type&;
using iterator_category = std::forward_iterator_tag;

iterator(uint8_t* buf) : buf(buf) {}
iterator(uint8_t* buf) : m_buf(buf) {}

[[nodiscard]] decltype(auto) operator*() const
{
constexpr bool is_trivial = IsTriviallyCopyable<T>;
if constexpr (is_trivial)
{
assert(test_correct_alignment<T>(buf));
return read_value<T>(buf);
assert(test_correct_alignment<T>(m_buf));
return read_value<T>(m_buf);
}
else
{
Expand All @@ -395,11 +394,11 @@ class View<Vector<T>>
constexpr bool is_trivial = IsTriviallyCopyable<T>;
if constexpr (is_trivial)
{
buf += sizeof(T);
m_buf += sizeof(T);
}
else
{
buf += sizeof(offset_type);
m_buf += sizeof(offset_type);
}
return *this;
}
Expand All @@ -411,7 +410,7 @@ class View<Vector<T>>
return tmp;
}

[[nodiscard]] bool operator==(const iterator& other) const { return buf == other.buf; }
[[nodiscard]] bool operator==(const iterator& other) const { return m_buf == other.m_buf; }

[[nodiscard]] bool operator!=(const iterator& other) const { return !(*this == other); }
};
Expand Down Expand Up @@ -463,7 +462,7 @@ class View<Vector<T>>
}
else
{
return View<T>(m_buf + read_value<offset_type>(m_buf));
return View<T>(buf + read_value<offset_type>(buf));
}
}

Expand Down Expand Up @@ -657,7 +656,7 @@ class ConstView<Vector<T>>
}
else
{
return View<T>(m_buf + read_value<offset_type>(m_buf));
return View<T>(buf + read_value<offset_type>(buf));
}
}

Expand Down
1 change: 0 additions & 1 deletion tests/unit/types/bitset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include <flatmemory/flatmemory.hpp>
#include <gtest/gtest.h>
#include <string>

namespace flatmemory::tests
{
Expand Down

0 comments on commit 2bbbb52

Please sign in to comment.