summaryrefslogtreecommitdiff
path: root/asl
diff options
context:
space:
mode:
authorSteven Le Rouzic <steven.lerouzic@gmail.com>2025-03-07 00:00:43 +0100
committerSteven Le Rouzic <steven.lerouzic@gmail.com>2025-03-07 00:00:43 +0100
commit636882316b5191931e144212d93665c10859ac95 (patch)
tree740f76daceee5bff223b790a4eb91f4e59c5be61 /asl
parentf0cccbe3285c039553e1fd8b5a5c7830d6087974 (diff)
Some work on clang-tidy-ing things up
Diffstat (limited to 'asl')
-rw-r--r--asl/base/defer_tests.cpp10
-rw-r--r--asl/base/meta.hpp2
-rw-r--r--asl/containers/buffer.hpp9
-rw-r--r--asl/containers/buffer_tests.cpp24
-rw-r--r--asl/containers/hash_map_tests.cpp1
-rw-r--r--asl/containers/hash_set.hpp7
-rw-r--r--asl/containers/hash_set_tests.cpp15
-rw-r--r--asl/containers/intrusive_list.hpp2
-rw-r--r--asl/containers/intrusive_list_tests.cpp2
-rw-r--r--asl/formatting/format.cpp4
-rw-r--r--asl/formatting/format_float.cpp14
-rw-r--r--asl/hashing/hash.hpp2
-rw-r--r--asl/hashing/hash_tests.cpp57
-rw-r--r--asl/io/print.cpp2
-rw-r--r--asl/strings/string.hpp10
-rw-r--r--asl/strings/string_builder_tests.cpp4
-rw-r--r--asl/strings/string_tests.cpp4
-rw-r--r--asl/strings/string_view_tests.cpp16
-rw-r--r--asl/types/box_tests.cpp2
-rw-r--r--asl/types/option_tests.cpp18
-rw-r--r--asl/types/span_tests.cpp42
-rw-r--r--asl/types/status.cpp6
-rw-r--r--asl/types/status_or_tests.cpp14
-rw-r--r--asl/types/status_tests.cpp12
24 files changed, 145 insertions, 134 deletions
diff --git a/asl/base/defer_tests.cpp b/asl/base/defer_tests.cpp
index 4c53f2c..097a6a8 100644
--- a/asl/base/defer_tests.cpp
+++ b/asl/base/defer_tests.cpp
@@ -10,25 +10,25 @@ ASL_TEST(defer)
uint32_t a = 0;
{
- ASL_DEFER [&a]() { a |= 1; };
+ ASL_DEFER [&a]() { a |= 1U; };
ASL_TEST_EXPECT(a == 0);
{
- ASL_DEFER [&a]() { a |= 2; };
- ASL_DEFER [&a]() { a |= 4; };
+ ASL_DEFER [&a]() { a |= 2U; };
+ ASL_DEFER [&a]() { a |= 4U; };
ASL_TEST_EXPECT(a == 0);
}
ASL_TEST_EXPECT(a == 6);
{
- ASL_DEFER [&a]() { a |= 8; };
+ ASL_DEFER [&a]() { a |= 8U; };
ASL_TEST_EXPECT(a == 6);
}
ASL_TEST_EXPECT(a == 14);
- ASL_DEFER [&a]() { a |= 16; };
+ ASL_DEFER [&a]() { a |= 16U; };
ASL_TEST_EXPECT(a == 14);
}
diff --git a/asl/base/meta.hpp b/asl/base/meta.hpp
index b798eeb..06c7c59 100644
--- a/asl/base/meta.hpp
+++ b/asl/base/meta.hpp
@@ -153,7 +153,7 @@ template<typename T> struct _tame_helper { using type = T; };
#define TAME_HELPER_IMPL(TRAILING) \
template<typename R, typename... Args> \
- struct _tame_helper<R(Args...) TRAILING> { using type = R(Args...); }
+ struct _tame_helper<R(Args...) TRAILING> { using type = R(Args...); } // NOLINT(*-parentheses)
TAME_HELPER_IMPL();
TAME_HELPER_IMPL(&);
diff --git a/asl/containers/buffer.hpp b/asl/containers/buffer.hpp
index 386b52a..c7fc01f 100644
--- a/asl/containers/buffer.hpp
+++ b/asl/containers/buffer.hpp
@@ -80,7 +80,7 @@ private:
{
return is_on_heap(size_encoded)
? static_cast<isize_t>(size_encoded & (~kOnHeapMask))
- : static_cast<isize_t>(size_encoded >> 56);
+ : static_cast<isize_t>(size_encoded >> 56U);
}
}
@@ -110,7 +110,7 @@ private:
constexpr void set_size_inline(isize_t new_size)
{
ASL_ASSERT(new_size >= 0 && new_size <= kInlineCapacity);
- size_t size_encoded = (load_size_encoded() & size_t{0x00ff'ffff'ffff'ffff}) | (bit_cast<size_t>(new_size) << 56);
+ size_t size_encoded = (load_size_encoded() & size_t{0x00ff'ffff'ffff'ffff}) | (bit_cast<size_t>(new_size) << 56U);
store_size_encoded(size_encoded);
}
@@ -328,12 +328,12 @@ public:
if (currently_on_heap && trivially_move_constructible<T>)
{
- m_data = reinterpret_cast<T*>(m_allocator.realloc(m_data, old_layout, new_layout));
+ m_data = static_cast<T*>(m_allocator.realloc(m_data, old_layout, new_layout));
m_capacity = new_capacity;
return;
}
- T* new_data = reinterpret_cast<T*>(m_allocator.alloc(new_layout));
+ T* new_data = static_cast<T*>(m_allocator.alloc(new_layout));
relocate_uninit_n(new_data, old_data, current_size);
@@ -394,6 +394,7 @@ public:
}
else
{
+ // NOLINTNEXTLINE(*-reinterpret-cast)
return self.is_on_heap() ? return_type{ self.m_data } : reinterpret_cast<return_type>(&self);
}
}
diff --git a/asl/containers/buffer_tests.cpp b/asl/containers/buffer_tests.cpp
index af79c92..2538e92 100644
--- a/asl/containers/buffer_tests.cpp
+++ b/asl/containers/buffer_tests.cpp
@@ -24,7 +24,7 @@ ASL_TEST(default_size)
ASL_TEST_EXPECT(b1.capacity() == 5);
ASL_TEST_EXPECT(static_cast<const void*>(b1.data()) == &b1);
- asl::buffer<Big> b2;
+ const asl::buffer<Big> b2;
ASL_TEST_EXPECT(b2.size() == 0);
ASL_TEST_EXPECT(b2.capacity() == 0);
ASL_TEST_EXPECT(b2.data() == nullptr);
@@ -34,6 +34,7 @@ struct CounterAllocator
{
isize_t* count;
+ [[nodiscard]]
void* alloc(const asl::layout& layout) const
{
*count += 1;
@@ -76,6 +77,7 @@ struct IncompatibleAllocator
};
static_assert(asl::allocator<IncompatibleAllocator>);
+// NOLINTNEXTLINE(*-complexity)
ASL_TEST(reserve_capacity)
{
isize_t count = 0;
@@ -105,6 +107,7 @@ ASL_TEST(reserve_capacity)
ASL_TEST_EXPECT(count == 2);
}
+// NOLINTNEXTLINE(*-complexity)
ASL_TEST(push)
{
asl::buffer<int32_t> b;
@@ -137,7 +140,7 @@ ASL_TEST(push)
ASL_TEST(from_span)
{
- int data[] = {1, 2, 4, 8};
+ const int data[] = {1, 2, 4, 8};
asl::buffer<int> b{data};
ASL_TEST_EXPECT(b.size() == 4);
@@ -157,12 +160,14 @@ struct MoveableType
MoveableType(MoveableType&& other) : moved{other.moved + 1}, value{other.value} {}
MoveableType& operator=(const MoveableType&) = delete;
MoveableType& operator=(MoveableType&&) = delete;
+ ~MoveableType() = default;
};
static_assert(!asl::trivially_copy_constructible<MoveableType>);
static_assert(!asl::trivially_move_constructible<MoveableType>);
static_assert(!asl::copyable<MoveableType>);
static_assert(asl::move_constructible<MoveableType>);
+// NOLINTNEXTLINE(*-complexity)
ASL_TEST(push_move)
{
asl::buffer<MoveableType> b;
@@ -275,14 +280,13 @@ ASL_TEST(move_construct_from_heap)
buf.push(&d[2]);
{
- asl::buffer<DestructorObserver> buf2(std::move(buf));
+ const asl::buffer<DestructorObserver> buf2(std::move(buf));
ASL_TEST_EXPECT(buf2.size() == 3);
ASL_TEST_EXPECT(d[0] == false);
ASL_TEST_EXPECT(d[1] == false);
ASL_TEST_EXPECT(d[2] == false);
}
- ASL_TEST_EXPECT(buf.size() == 0);
ASL_TEST_EXPECT(d[0] == true);
ASL_TEST_EXPECT(d[1] == true);
ASL_TEST_EXPECT(d[2] == true);
@@ -299,7 +303,6 @@ ASL_TEST(move_construct_inline_trivial)
ASL_TEST_EXPECT(buf2[1] == 2U);
ASL_TEST_EXPECT(buf2.size() == 2);
- ASL_TEST_EXPECT(buf.size() == 0);
}
ASL_TEST(move_construct_from_inline_non_trivial)
@@ -310,17 +313,17 @@ ASL_TEST(move_construct_from_inline_non_trivial)
buf.push(&d[1]);
{
- asl::buffer<DestructorObserver> buf2(std::move(buf));
+ const asl::buffer<DestructorObserver> buf2(std::move(buf));
ASL_TEST_EXPECT(buf2.size() == 2);
ASL_TEST_EXPECT(d[0] == false);
ASL_TEST_EXPECT(d[1] == false);
}
- ASL_TEST_EXPECT(buf.size() == 0);
ASL_TEST_EXPECT(d[0] == true);
ASL_TEST_EXPECT(d[1] == true);
}
+// NOLINTNEXTLINE(*-complexity)
ASL_TEST(move_assign_from_heap)
{
bool d[6]{};
@@ -346,7 +349,6 @@ ASL_TEST(move_assign_from_heap)
buf2 = std::move(buf);
- ASL_TEST_EXPECT(buf.size() == 0);
ASL_TEST_EXPECT(buf2.size() == 3);
ASL_TEST_EXPECT(d[0] == false);
@@ -384,7 +386,6 @@ ASL_TEST(move_assign_trivial_heap_to_inline)
ASL_TEST_EXPECT(alloc_count == 1);
ASL_TEST_EXPECT(buf.size() == 3);
- ASL_TEST_EXPECT(buf2.size() == 0);
ASL_TEST_EXPECT(buf[0] == 3);
ASL_TEST_EXPECT(buf[1] == 4);
ASL_TEST_EXPECT(buf[2] == 5);
@@ -408,12 +409,12 @@ ASL_TEST(move_assign_trivial_inline_to_heap)
buf2 = std::move(buf);
ASL_TEST_EXPECT(alloc_count == 1);
- ASL_TEST_EXPECT(buf.size() == 0);
ASL_TEST_EXPECT(buf2.size() == 2);
ASL_TEST_EXPECT(buf2[0] == 1);
ASL_TEST_EXPECT(buf2[1] == 2);
}
+// NOLINTNEXTLINE(*-complexity)
ASL_TEST(move_assign_inline_to_heap)
{
bool d[6]{};
@@ -432,7 +433,6 @@ ASL_TEST(move_assign_inline_to_heap)
buf2 = std::move(buf);
- ASL_TEST_EXPECT(buf.size() == 0);
ASL_TEST_EXPECT(buf2.size() == 2);
ASL_TEST_EXPECT(d[0] == false);
ASL_TEST_EXPECT(d[1] == false);
@@ -450,6 +450,7 @@ ASL_TEST(move_assign_inline_to_heap)
ASL_TEST_EXPECT(d[5] == true);
}
+// NOLINTNEXTLINE(*-complexity)
ASL_TEST(move_assign_from_inline_incompatible_allocator)
{
bool d[6]{};
@@ -468,7 +469,6 @@ ASL_TEST(move_assign_from_inline_incompatible_allocator)
buf2 = std::move(buf);
- ASL_TEST_EXPECT(buf.size() == 0);
ASL_TEST_EXPECT(buf2.size() == 2);
ASL_TEST_EXPECT(d[0] == false);
ASL_TEST_EXPECT(d[1] == false);
diff --git a/asl/containers/hash_map_tests.cpp b/asl/containers/hash_map_tests.cpp
index 9652e2f..fe8a284 100644
--- a/asl/containers/hash_map_tests.cpp
+++ b/asl/containers/hash_map_tests.cpp
@@ -5,6 +5,7 @@
#include "asl/testing/testing.hpp"
#include "asl/containers/hash_map.hpp"
+// NOLINTNEXTLINE(*-complexity)
ASL_TEST(default)
{
asl::hash_map<int, int> map;
diff --git a/asl/containers/hash_set.hpp b/asl/containers/hash_set.hpp
index 61346fa..02a8036 100644
--- a/asl/containers/hash_set.hpp
+++ b/asl/containers/hash_set.hpp
@@ -75,7 +75,7 @@ protected:
constexpr isize_t max_size() const
{
// Max load factor is 75%
- return (m_capacity >> 1) + (m_capacity >> 2);
+ return (m_capacity >> 1) + (m_capacity >> 2); // NOLINT(*-signed-bitwise)
}
static isize_t size_to_capacity(isize_t size)
@@ -131,8 +131,8 @@ protected:
{
ASL_ASSERT(new_capacity >= kMinCapacity && is_pow2(new_capacity) && new_capacity > m_capacity);
- auto* new_tags = reinterpret_cast<uint8_t*>(m_allocator.alloc(layout::array<uint8_t>(new_capacity)));
- auto* new_values = reinterpret_cast<maybe_uninit<T>*>(m_allocator.alloc(layout::array<maybe_uninit<T>>(new_capacity)));
+ auto* new_tags = static_cast<uint8_t*>(m_allocator.alloc(layout::array<uint8_t>(new_capacity)));
+ auto* new_values = static_cast<maybe_uninit<T>*>(m_allocator.alloc(layout::array<maybe_uninit<T>>(new_capacity)));
asl::memzero(new_tags, new_capacity);
isize_t new_size = 0;
@@ -228,7 +228,6 @@ protected:
result.tag = static_cast<uint8_t>(hash & kHashMask) | kHasValue;
// NOLINTBEGIN(*-pointer-arithmetic)
-
for (
isize_t i = starting_index;
i != starting_index || result.first_available_index < 0;
diff --git a/asl/containers/hash_set_tests.cpp b/asl/containers/hash_set_tests.cpp
index 515fe76..8f42e50 100644
--- a/asl/containers/hash_set_tests.cpp
+++ b/asl/containers/hash_set_tests.cpp
@@ -10,7 +10,7 @@
ASL_TEST(empty)
{
- asl::hash_set<int> set;
+ const asl::hash_set<int> set;
ASL_TEST_EXPECT(set.size() == 0);
@@ -42,7 +42,7 @@ ASL_TEST(a_bunch_of_ints)
{
asl::hash_set<int> set;
- int count = 3000;
+ const int count = 3000;
for (int i = 0; i < count; ++i)
{
@@ -98,6 +98,7 @@ struct CustomHasher
}
};
+// NOLINTNEXTLINE(*-complexity)
ASL_TEST(destructor_and_remove)
{
static constexpr int kCount = 200;
@@ -113,9 +114,9 @@ ASL_TEST(destructor_and_remove)
ASL_TEST_EXPECT(set.size() == kCount);
- for (int i = 0; i < kCount; ++i)
+ for (const bool i : destroyed)
{
- ASL_TEST_EXPECT(!destroyed[i]); // NOLINT
+ ASL_TEST_EXPECT(!i); // NOLINT
}
for (int i = 0; i < kCount; i += 2)
@@ -132,9 +133,9 @@ ASL_TEST(destructor_and_remove)
}
}
- for (int i = 0; i < kCount; ++i)
+ for (const bool i : destroyed)
{
- ASL_TEST_EXPECT(destroyed[i]); // NOLINT
+ ASL_TEST_EXPECT(i); // NOLINT
}
}
@@ -147,7 +148,7 @@ ASL_TEST(copy)
set1.insert(i);
}
- asl::hash_set<int> set2 = set1;
+ const asl::hash_set<int> set2 = set1;
asl::hash_set<int> set3;
set3 = set1;
diff --git a/asl/containers/intrusive_list.hpp b/asl/containers/intrusive_list.hpp
index 2af02eb..a58bbfd 100644
--- a/asl/containers/intrusive_list.hpp
+++ b/asl/containers/intrusive_list.hpp
@@ -188,5 +188,5 @@ public:
}
};
-}
+} // namespace asl
diff --git a/asl/containers/intrusive_list_tests.cpp b/asl/containers/intrusive_list_tests.cpp
index 4e19237..146ab6b 100644
--- a/asl/containers/intrusive_list_tests.cpp
+++ b/asl/containers/intrusive_list_tests.cpp
@@ -23,6 +23,7 @@ ASL_TEST(empty_list)
ASL_TEST_EXPECT(list.back() == nullptr);
}
+// NOLINTNEXTLINE(*-complexity)
ASL_TEST(push_front)
{
IntNode one{1};
@@ -75,6 +76,7 @@ ASL_TEST(push_front)
ASL_TEST_ASSERT(it == end);
}
+// NOLINTNEXTLINE(*-complexity)
ASL_TEST(push_back)
{
IntNode one{1};
diff --git a/asl/formatting/format.cpp b/asl/formatting/format.cpp
index 4f35a52..732d89f 100644
--- a/asl/formatting/format.cpp
+++ b/asl/formatting/format.cpp
@@ -151,7 +151,7 @@ asl::string_view asl::format_uint64(uint64_t v, asl::span<char, kMaxUint64Digits
while (v >= 100)
{
- uint64_t x = v % 100;
+ const uint64_t x = v % 100;
v /= 100;
write_two(s_pairs.subspan(static_cast<isize_t>(x * 2)).first<2>());
}
@@ -195,7 +195,7 @@ void asl::AslFormat(Formatter& f, int64_t v)
if (v < 0)
{
f.write("-");
- uint64_t absolute_value = ~(bit_cast<uint64_t>(v) - 1);
+ const uint64_t absolute_value = ~(bit_cast<uint64_t>(v) - 1);
AslFormat(f, absolute_value);
}
else
diff --git a/asl/formatting/format_float.cpp b/asl/formatting/format_float.cpp
index aa113c6..3802ff9 100644
--- a/asl/formatting/format_float.cpp
+++ b/asl/formatting/format_float.cpp
@@ -25,12 +25,12 @@ static constexpr char kZeros[kZeroCount] = {
static constexpr bool is_zero(float x)
{
- return (asl::bit_cast<uint32_t>(x) & 0x7fff'ffff) == 0;
+ return (asl::bit_cast<uint32_t>(x) & 0x7fff'ffffU) == 0;
}
static constexpr bool is_zero(double x)
{
- return (asl::bit_cast<uint64_t>(x) & 0x7fff'ffff'ffff'ffff) == 0;
+ return (asl::bit_cast<uint64_t>(x) & 0x7fff'ffff'ffff'ffffULL) == 0;
}
template<asl::is_floating_point T>
@@ -66,15 +66,15 @@ static void format_float(asl::Formatter& f, T value)
if (decimal.is_negative) { f.write("-"); }
char buffer[20];
- asl::string_view digits = asl::format_uint64(decimal.significand, buffer);
+ const asl::string_view digits = asl::format_uint64(decimal.significand, buffer);
if (decimal.exponent >= 0)
{
f.write(digits);
while (decimal.exponent > 0)
{
- isize_t to_write = asl::min(static_cast<isize_t>(decimal.exponent), kZeroCount);
- f.write(asl::string_view(kZeros, to_write));
+ const isize_t to_write = asl::min(static_cast<isize_t>(decimal.exponent), kZeroCount);
+ f.write(asl::string_view(static_cast<const char*>(kZeros), to_write));
decimal.exponent -= to_write;
}
}
@@ -86,8 +86,8 @@ static void format_float(asl::Formatter& f, T value)
decimal.exponent = -decimal.exponent - static_cast<int>(digits.size());
while (decimal.exponent > 0)
{
- isize_t to_write = asl::min(static_cast<isize_t>(decimal.exponent), kZeroCount);
- f.write(asl::string_view(kZeros, to_write));
+ const isize_t to_write = asl::min(static_cast<isize_t>(decimal.exponent), kZeroCount);
+ f.write(asl::string_view(static_cast<const char*>(kZeros), to_write));
decimal.exponent -= to_write;
}
f.write(digits);
diff --git a/asl/hashing/hash.hpp b/asl/hashing/hash.hpp
index 443a774..f8987df 100644
--- a/asl/hashing/hash.hpp
+++ b/asl/hashing/hash.hpp
@@ -80,7 +80,7 @@ struct HashState
{
auto bytes = as_bytes(s);
auto hashed = city_hash::CityHash128WithSeed(
- reinterpret_cast<const char*>(bytes.data()),
+ reinterpret_cast<const char*>(bytes.data()), // NOLINT(*-reinterpret-cast)
static_cast<size_t>(bytes.size()),
h.state);
return HashState{hashed};
diff --git a/asl/hashing/hash_tests.cpp b/asl/hashing/hash_tests.cpp
index e4e69bf..4cb2f6e 100644
--- a/asl/hashing/hash_tests.cpp
+++ b/asl/hashing/hash_tests.cpp
@@ -29,10 +29,10 @@ static_assert(asl::hashable<int64_t>);
ASL_TEST(integers)
{
- uint64_t a = asl::hash_value<uint16_t>(45);
- uint64_t b = asl::hash_value<uint16_t>(45);
- uint64_t c = asl::hash_value<uint16_t>(46);
- uint64_t d = asl::hash_value<uint32_t>(45);
+ const uint64_t a = asl::hash_value<uint16_t>(45);
+ const uint64_t b = asl::hash_value<uint16_t>(45);
+ const uint64_t c = asl::hash_value<uint16_t>(46);
+ const uint64_t d = asl::hash_value<uint32_t>(45);
ASL_TEST_EXPECT(a == b);
ASL_TEST_EXPECT(a != c);
@@ -187,19 +187,19 @@ static_assert(asl::uniquely_represented<asl::option<NonZero>>);
ASL_TEST(option)
{
- asl::option<int> int1 = 0;
- asl::option<int> int2 = 0;
- asl::option<int> int3 = 1;
- asl::option<int> int4 = asl::nullopt;
+ const asl::option<int> int1 = 0;
+ const asl::option<int> int2 = 0;
+ const asl::option<int> int3 = 1;
+ const asl::option<int> int4 = asl::nullopt;
ASL_TEST_EXPECT(asl::hash_value(int1) == asl::hash_value(int2));
ASL_TEST_EXPECT(asl::hash_value(int1) != asl::hash_value(int3));
ASL_TEST_EXPECT(asl::hash_value(int1) != asl::hash_value(int4));
- asl::option<NonZero> noz1{8};
- asl::option<NonZero> noz2{8};
- asl::option<NonZero> noz3{9};
- asl::option<NonZero> noz4 = asl::nullopt;
+ const asl::option<NonZero> noz1{8};
+ const asl::option<NonZero> noz2{8};
+ const asl::option<NonZero> noz3{9};
+ const asl::option<NonZero> noz4 = asl::nullopt;
ASL_TEST_EXPECT(asl::hash_value(noz1) == asl::hash_value(noz2));
ASL_TEST_EXPECT(asl::hash_value(noz1) != asl::hash_value(noz3));
@@ -208,17 +208,18 @@ ASL_TEST(option)
static_assert(asl::hashable<asl::status>);
+// NOLINTNEXTLINE(*-cognitive-complexity)
ASL_TEST(status)
{
- asl::status s1 = asl::ok();
- asl::status s2 = asl::ok();
- asl::status s3 = asl::internal_error();
- asl::status s4 = asl::internal_error();
- asl::status s5 = asl::runtime_error();
- asl::status s6 = asl::internal_error("Oh, no!");
- asl::status s7 = asl::internal_error("Oh, no!");
- asl::status s8 = asl::internal_error("Oh, no");
- asl::status s9 = asl::runtime_error("Oh, no!");
+ const asl::status s1 = asl::ok();
+ const asl::status s2 = asl::ok();
+ const asl::status s3 = asl::internal_error();
+ const asl::status s4 = asl::internal_error();
+ const asl::status s5 = asl::runtime_error();
+ const asl::status s6 = asl::internal_error("Oh, no!");
+ const asl::status s7 = asl::internal_error("Oh, no!");
+ const asl::status s8 = asl::internal_error("Oh, no");
+ const asl::status s9 = asl::runtime_error("Oh, no!");
ASL_TEST_EXPECT(asl::hash_value(s1) == asl::hash_value(s2));
ASL_TEST_EXPECT(asl::hash_value(s3) == asl::hash_value(s4));
@@ -244,13 +245,13 @@ static_assert(!asl::hashable<asl::status_or<int*>>);
ASL_TEST(status_or)
{
- asl::status_or<int> s1 = 42;
- asl::status_or<int> s2 = 42;
- asl::status_or<int> s3 = 43;
- asl::status_or<int> s4 = asl::runtime_error();
- asl::status_or<int> s5 = asl::runtime_error();
- asl::status_or<int> s6 = asl::runtime_error("Hello");
- asl::status_or<int> s7 = asl::runtime_error("Hello");
+ const asl::status_or<int> s1 = 42;
+ const asl::status_or<int> s2 = 42;
+ const asl::status_or<int> s3 = 43;
+ const asl::status_or<int> s4 = asl::runtime_error();
+ const asl::status_or<int> s5 = asl::runtime_error();
+ const asl::status_or<int> s6 = asl::runtime_error("Hello");
+ const asl::status_or<int> s7 = asl::runtime_error("Hello");
ASL_TEST_EXPECT(asl::hash_value(s1) == asl::hash_value(s2));
ASL_TEST_EXPECT(asl::hash_value(s4) == asl::hash_value(s5));
diff --git a/asl/io/print.cpp b/asl/io/print.cpp
index 5b48eef..173b3f7 100644
--- a/asl/io/print.cpp
+++ b/asl/io/print.cpp
@@ -18,7 +18,7 @@ public:
void write(asl::span<const asl::byte> s) override
{
- fwrite(s.data(), 1, static_cast<size_t>(s.size()), m_handle);
+ (void)fwrite(s.data(), 1, static_cast<size_t>(s.size()), m_handle);
}
};
diff --git a/asl/strings/string.hpp b/asl/strings/string.hpp
index 0f70228..7254762 100644
--- a/asl/strings/string.hpp
+++ b/asl/strings/string.hpp
@@ -26,7 +26,7 @@ public:
constexpr string() requires default_constructible<Allocator> = default;
explicit constexpr string(Allocator allocator) : m_buffer{std::move(allocator)} {}
- // NOLINTNEXTLINE(*-explicit-conversions)
+ // NOLINTNEXTLINE(*explicit*)
constexpr string(string_view sv)
requires default_constructible<Allocator>
: m_buffer{sv.as_span()}
@@ -44,16 +44,16 @@ public:
constexpr string& operator=(const string&) requires copy_assignable<Allocator> = default;
constexpr string& operator=(string&&) = default;
- constexpr isize_t size() const { return m_buffer.size(); }
- constexpr const char* data() const { return m_buffer.data(); }
+ [[nodiscard]] constexpr isize_t size() const { return m_buffer.size(); }
+ [[nodiscard]] constexpr const char* data() const { return m_buffer.data(); }
- // NOLINTNEXTLINE(*-explicit-conversions)
+ // NOLINTNEXTLINE(*explicit*)
constexpr operator string_view() const
{
return as_string_view();
}
- constexpr string_view as_string_view() const
+ [[nodiscard]] constexpr string_view as_string_view() const
{
auto span = m_buffer.as_span();
return string_view{span.data(), span.size()};
diff --git a/asl/strings/string_builder_tests.cpp b/asl/strings/string_builder_tests.cpp
index dadfc88..ac7a3da 100644
--- a/asl/strings/string_builder_tests.cpp
+++ b/asl/strings/string_builder_tests.cpp
@@ -14,13 +14,13 @@ ASL_TEST(string_builder)
ASL_TEST_EXPECT(b.as_string_view() == "abcdefg");
- asl::string s = b.as_string();
+ const asl::string s = b.as_string();
ASL_TEST_EXPECT(s == "abcdefg");
}
ASL_TEST(string_builder_rvalue)
{
- asl::string s = asl::StringBuilder{}.push('a').push("bcdef").push('g').finish();
+ const asl::string s = asl::StringBuilder{}.push('a').push("bcdef").push('g').finish();
ASL_TEST_EXPECT(s == "abcdefg");
}
diff --git a/asl/strings/string_tests.cpp b/asl/strings/string_tests.cpp
index 4ef6185..90d1dbb 100644
--- a/asl/strings/string_tests.cpp
+++ b/asl/strings/string_tests.cpp
@@ -8,7 +8,7 @@
ASL_TEST(default)
{
- asl::string s;
+ const asl::string s;
ASL_TEST_ASSERT(s.size() == 0);
ASL_TEST_ASSERT(s.as_string_view().size() == 0);
ASL_TEST_ASSERT(s == ""_sv);
@@ -17,7 +17,7 @@ ASL_TEST(default)
ASL_TEST(from_string_view)
{
- asl::string s = "hello"_sv;
+ const asl::string s = "hello"_sv;
ASL_TEST_ASSERT(s.size() == 5);
ASL_TEST_ASSERT(s == "hello"_sv);
}
diff --git a/asl/strings/string_view_tests.cpp b/asl/strings/string_view_tests.cpp
index 33a8d71..b77c4ff 100644
--- a/asl/strings/string_view_tests.cpp
+++ b/asl/strings/string_view_tests.cpp
@@ -10,20 +10,20 @@ static_assert(asl::trivially_copy_constructible<asl::string_view>);
ASL_TEST(default)
{
- asl::string_view s1;
+ const asl::string_view s1;
ASL_TEST_EXPECT(s1.is_empty());
- asl::string_view s2 = nullptr;
+ const asl::string_view s2 = nullptr;
ASL_TEST_EXPECT(s2.is_empty());
}
ASL_TEST(from_literal)
{
- asl::string_view s1 = "Hello"_sv;
+ const asl::string_view s1 = "Hello"_sv;
ASL_TEST_ASSERT(s1.size() == 5);
ASL_TEST_EXPECT(asl::memcmp(s1.data(), "Hello", 5) == 0);
- asl::string_view s2 = ""_sv;
+ const asl::string_view s2 = ""_sv;
ASL_TEST_EXPECT(s2.is_empty());
}
@@ -47,7 +47,7 @@ ASL_TEST(from_zstr)
ASL_TEST(substr1)
{
- asl::string_view s1 = "abcd";
+ const asl::string_view s1 = "abcd";
asl::string_view s2 = s1.substr(0);
ASL_TEST_ASSERT(s2.size() == 4);
@@ -63,7 +63,7 @@ ASL_TEST(substr1)
ASL_TEST(substr2)
{
- asl::string_view s1 = "abcd";
+ const asl::string_view s1 = "abcd";
asl::string_view s2 = s1.substr(0, 4);
ASL_TEST_ASSERT(s2.size() == 4);
@@ -82,7 +82,7 @@ ASL_TEST(substr2)
ASL_TEST(first)
{
- asl::string_view s1 = "abcd";
+ const asl::string_view s1 = "abcd";
asl::string_view s2 = s1.first(0);
ASL_TEST_ASSERT(s2.size() == 0);
@@ -98,7 +98,7 @@ ASL_TEST(first)
ASL_TEST(last)
{
- asl::string_view s1 = "abcd";
+ const asl::string_view s1 = "abcd";
asl::string_view s2 = s1.last(0);
ASL_TEST_ASSERT(s2.size() == 0);
diff --git a/asl/types/box_tests.cpp b/asl/types/box_tests.cpp
index d7281ed..b3c55b2 100644
--- a/asl/types/box_tests.cpp
+++ b/asl/types/box_tests.cpp
@@ -81,7 +81,7 @@ ASL_TEST(niche)
ASL_TEST_EXPECT(destroyed);
}
-class Base
+class Base // NOLINT
{
public:
virtual ~Base() = default;
diff --git a/asl/types/option_tests.cpp b/asl/types/option_tests.cpp
index 2dff6f5..d08c94a 100644
--- a/asl/types/option_tests.cpp
+++ b/asl/types/option_tests.cpp
@@ -99,8 +99,8 @@ static_assert(!asl::trivially_move_assignable<asl::option<MoveableOnly>>);
ASL_TEST(make_null)
{
- asl::option<int> a;
- asl::option<int> b = asl::nullopt;
+ const asl::option<int> a;
+ const asl::option<int> b = asl::nullopt;
ASL_TEST_EXPECT(!a.has_value());
ASL_TEST_EXPECT(!b.has_value());
@@ -108,7 +108,7 @@ ASL_TEST(make_null)
ASL_TEST(make_value)
{
- asl::option<int> a = 48;
+ const asl::option<int> a = 48;
ASL_TEST_EXPECT(a.has_value());
}
@@ -132,7 +132,7 @@ ASL_TEST(call_destructor)
asl::option<DestructorObserver> opt(std::move(obs));
ASL_TEST_EXPECT(!destroyed);
- asl::option<DestructorObserver> opt2 = std::move(opt);
+ const asl::option<DestructorObserver> opt2 = std::move(opt);
ASL_TEST_EXPECT(!destroyed);
}
@@ -213,7 +213,7 @@ ASL_TEST(convert_move)
ASL_TEST_ASSERT(opt16.has_value());
ASL_TEST_EXPECT(opt16.value() == 8);
- opt8 = std::move(uint8_t{10});
+ opt8 = uint8_t{10};
ASL_TEST_ASSERT(opt8.has_value());
ASL_TEST_EXPECT(opt8.value() == 10);
@@ -227,8 +227,8 @@ ASL_TEST(convert_move)
ASL_TEST(value_or)
{
- asl::option<int> a = asl::nullopt;
- asl::option<int> b = 2;
+ const asl::option<int> a = asl::nullopt;
+ const asl::option<int> b = 2;
ASL_TEST_EXPECT(a.value_or(5) == 5);
ASL_TEST_EXPECT(b.value_or(5) == 2);
@@ -296,8 +296,8 @@ ASL_TEST(transform)
ASL_TEST(or_else)
{
- asl::option<int> a = 5;
- asl::option<int> b;
+ const asl::option<int> a = 5;
+ const asl::option<int> b;
auto fn = []() -> asl::option<int> { return 12; };
diff --git a/asl/types/span_tests.cpp b/asl/types/span_tests.cpp
index 47749cf..55471ab 100644
--- a/asl/types/span_tests.cpp
+++ b/