Some work on clang-tidy-ing things up

This commit is contained in:
2025-03-07 00:00:43 +01:00
parent f0cccbe328
commit 636882316b
26 changed files with 151 additions and 134 deletions

View File

@ -13,3 +13,8 @@ Checks:
- "-*noexcept*" - "-*noexcept*"
- "-*-magic-numbers" - "-*-magic-numbers"
- "-*-named-parameter" - "-*-named-parameter"
- "-misc-include-cleaner"
- "-google-runtime-int"
- "-bugprone-easily-swappable-parameters"
- "-*-signed-bitwise"
- "-*-avoid-do-while"

View File

@ -10,25 +10,25 @@ ASL_TEST(defer)
uint32_t a = 0; uint32_t a = 0;
{ {
ASL_DEFER [&a]() { a |= 1; }; ASL_DEFER [&a]() { a |= 1U; };
ASL_TEST_EXPECT(a == 0); ASL_TEST_EXPECT(a == 0);
{ {
ASL_DEFER [&a]() { a |= 2; }; ASL_DEFER [&a]() { a |= 2U; };
ASL_DEFER [&a]() { a |= 4; }; ASL_DEFER [&a]() { a |= 4U; };
ASL_TEST_EXPECT(a == 0); ASL_TEST_EXPECT(a == 0);
} }
ASL_TEST_EXPECT(a == 6); ASL_TEST_EXPECT(a == 6);
{ {
ASL_DEFER [&a]() { a |= 8; }; ASL_DEFER [&a]() { a |= 8U; };
ASL_TEST_EXPECT(a == 6); ASL_TEST_EXPECT(a == 6);
} }
ASL_TEST_EXPECT(a == 14); ASL_TEST_EXPECT(a == 14);
ASL_DEFER [&a]() { a |= 16; }; ASL_DEFER [&a]() { a |= 16U; };
ASL_TEST_EXPECT(a == 14); ASL_TEST_EXPECT(a == 14);
} }

View File

@ -153,7 +153,7 @@ template<typename T> struct _tame_helper { using type = T; };
#define TAME_HELPER_IMPL(TRAILING) \ #define TAME_HELPER_IMPL(TRAILING) \
template<typename R, typename... Args> \ 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();
TAME_HELPER_IMPL(&); TAME_HELPER_IMPL(&);

View File

@ -80,7 +80,7 @@ private:
{ {
return is_on_heap(size_encoded) return is_on_heap(size_encoded)
? static_cast<isize_t>(size_encoded & (~kOnHeapMask)) ? 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) constexpr void set_size_inline(isize_t new_size)
{ {
ASL_ASSERT(new_size >= 0 && new_size <= kInlineCapacity); 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); store_size_encoded(size_encoded);
} }
@ -328,12 +328,12 @@ public:
if (currently_on_heap && trivially_move_constructible<T>) 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; m_capacity = new_capacity;
return; 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); relocate_uninit_n(new_data, old_data, current_size);
@ -394,6 +394,7 @@ public:
} }
else else
{ {
// NOLINTNEXTLINE(*-reinterpret-cast)
return self.is_on_heap() ? return_type{ self.m_data } : reinterpret_cast<return_type>(&self); return self.is_on_heap() ? return_type{ self.m_data } : reinterpret_cast<return_type>(&self);
} }
} }

View File

@ -24,7 +24,7 @@ ASL_TEST(default_size)
ASL_TEST_EXPECT(b1.capacity() == 5); ASL_TEST_EXPECT(b1.capacity() == 5);
ASL_TEST_EXPECT(static_cast<const void*>(b1.data()) == &b1); 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.size() == 0);
ASL_TEST_EXPECT(b2.capacity() == 0); ASL_TEST_EXPECT(b2.capacity() == 0);
ASL_TEST_EXPECT(b2.data() == nullptr); ASL_TEST_EXPECT(b2.data() == nullptr);
@ -34,6 +34,7 @@ struct CounterAllocator
{ {
isize_t* count; isize_t* count;
[[nodiscard]]
void* alloc(const asl::layout& layout) const void* alloc(const asl::layout& layout) const
{ {
*count += 1; *count += 1;
@ -76,6 +77,7 @@ struct IncompatibleAllocator
}; };
static_assert(asl::allocator<IncompatibleAllocator>); static_assert(asl::allocator<IncompatibleAllocator>);
// NOLINTNEXTLINE(*-complexity)
ASL_TEST(reserve_capacity) ASL_TEST(reserve_capacity)
{ {
isize_t count = 0; isize_t count = 0;
@ -105,6 +107,7 @@ ASL_TEST(reserve_capacity)
ASL_TEST_EXPECT(count == 2); ASL_TEST_EXPECT(count == 2);
} }
// NOLINTNEXTLINE(*-complexity)
ASL_TEST(push) ASL_TEST(push)
{ {
asl::buffer<int32_t> b; asl::buffer<int32_t> b;
@ -137,7 +140,7 @@ ASL_TEST(push)
ASL_TEST(from_span) ASL_TEST(from_span)
{ {
int data[] = {1, 2, 4, 8}; const int data[] = {1, 2, 4, 8};
asl::buffer<int> b{data}; asl::buffer<int> b{data};
ASL_TEST_EXPECT(b.size() == 4); ASL_TEST_EXPECT(b.size() == 4);
@ -157,12 +160,14 @@ struct MoveableType
MoveableType(MoveableType&& other) : moved{other.moved + 1}, value{other.value} {} MoveableType(MoveableType&& other) : moved{other.moved + 1}, value{other.value} {}
MoveableType& operator=(const MoveableType&) = delete; MoveableType& operator=(const MoveableType&) = delete;
MoveableType& operator=(MoveableType&&) = delete; MoveableType& operator=(MoveableType&&) = delete;
~MoveableType() = default;
}; };
static_assert(!asl::trivially_copy_constructible<MoveableType>); static_assert(!asl::trivially_copy_constructible<MoveableType>);
static_assert(!asl::trivially_move_constructible<MoveableType>); static_assert(!asl::trivially_move_constructible<MoveableType>);
static_assert(!asl::copyable<MoveableType>); static_assert(!asl::copyable<MoveableType>);
static_assert(asl::move_constructible<MoveableType>); static_assert(asl::move_constructible<MoveableType>);
// NOLINTNEXTLINE(*-complexity)
ASL_TEST(push_move) ASL_TEST(push_move)
{ {
asl::buffer<MoveableType> b; asl::buffer<MoveableType> b;
@ -275,14 +280,13 @@ ASL_TEST(move_construct_from_heap)
buf.push(&d[2]); 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(buf2.size() == 3);
ASL_TEST_EXPECT(d[0] == false); ASL_TEST_EXPECT(d[0] == false);
ASL_TEST_EXPECT(d[1] == false); ASL_TEST_EXPECT(d[1] == false);
ASL_TEST_EXPECT(d[2] == false); ASL_TEST_EXPECT(d[2] == false);
} }
ASL_TEST_EXPECT(buf.size() == 0);
ASL_TEST_EXPECT(d[0] == true); ASL_TEST_EXPECT(d[0] == true);
ASL_TEST_EXPECT(d[1] == true); ASL_TEST_EXPECT(d[1] == true);
ASL_TEST_EXPECT(d[2] == 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[1] == 2U);
ASL_TEST_EXPECT(buf2.size() == 2); ASL_TEST_EXPECT(buf2.size() == 2);
ASL_TEST_EXPECT(buf.size() == 0);
} }
ASL_TEST(move_construct_from_inline_non_trivial) ASL_TEST(move_construct_from_inline_non_trivial)
@ -310,17 +313,17 @@ ASL_TEST(move_construct_from_inline_non_trivial)
buf.push(&d[1]); 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(buf2.size() == 2);
ASL_TEST_EXPECT(d[0] == false); ASL_TEST_EXPECT(d[0] == false);
ASL_TEST_EXPECT(d[1] == false); ASL_TEST_EXPECT(d[1] == false);
} }
ASL_TEST_EXPECT(buf.size() == 0);
ASL_TEST_EXPECT(d[0] == true); ASL_TEST_EXPECT(d[0] == true);
ASL_TEST_EXPECT(d[1] == true); ASL_TEST_EXPECT(d[1] == true);
} }
// NOLINTNEXTLINE(*-complexity)
ASL_TEST(move_assign_from_heap) ASL_TEST(move_assign_from_heap)
{ {
bool d[6]{}; bool d[6]{};
@ -346,7 +349,6 @@ ASL_TEST(move_assign_from_heap)
buf2 = std::move(buf); buf2 = std::move(buf);
ASL_TEST_EXPECT(buf.size() == 0);
ASL_TEST_EXPECT(buf2.size() == 3); ASL_TEST_EXPECT(buf2.size() == 3);
ASL_TEST_EXPECT(d[0] == false); 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(alloc_count == 1);
ASL_TEST_EXPECT(buf.size() == 3); ASL_TEST_EXPECT(buf.size() == 3);
ASL_TEST_EXPECT(buf2.size() == 0);
ASL_TEST_EXPECT(buf[0] == 3); ASL_TEST_EXPECT(buf[0] == 3);
ASL_TEST_EXPECT(buf[1] == 4); ASL_TEST_EXPECT(buf[1] == 4);
ASL_TEST_EXPECT(buf[2] == 5); ASL_TEST_EXPECT(buf[2] == 5);
@ -408,12 +409,12 @@ ASL_TEST(move_assign_trivial_inline_to_heap)
buf2 = std::move(buf); buf2 = std::move(buf);
ASL_TEST_EXPECT(alloc_count == 1); ASL_TEST_EXPECT(alloc_count == 1);
ASL_TEST_EXPECT(buf.size() == 0);
ASL_TEST_EXPECT(buf2.size() == 2); ASL_TEST_EXPECT(buf2.size() == 2);
ASL_TEST_EXPECT(buf2[0] == 1); ASL_TEST_EXPECT(buf2[0] == 1);
ASL_TEST_EXPECT(buf2[1] == 2); ASL_TEST_EXPECT(buf2[1] == 2);
} }
// NOLINTNEXTLINE(*-complexity)
ASL_TEST(move_assign_inline_to_heap) ASL_TEST(move_assign_inline_to_heap)
{ {
bool d[6]{}; bool d[6]{};
@ -432,7 +433,6 @@ ASL_TEST(move_assign_inline_to_heap)
buf2 = std::move(buf); buf2 = std::move(buf);
ASL_TEST_EXPECT(buf.size() == 0);
ASL_TEST_EXPECT(buf2.size() == 2); ASL_TEST_EXPECT(buf2.size() == 2);
ASL_TEST_EXPECT(d[0] == false); ASL_TEST_EXPECT(d[0] == false);
ASL_TEST_EXPECT(d[1] == false); ASL_TEST_EXPECT(d[1] == false);
@ -450,6 +450,7 @@ ASL_TEST(move_assign_inline_to_heap)
ASL_TEST_EXPECT(d[5] == true); ASL_TEST_EXPECT(d[5] == true);
} }
// NOLINTNEXTLINE(*-complexity)
ASL_TEST(move_assign_from_inline_incompatible_allocator) ASL_TEST(move_assign_from_inline_incompatible_allocator)
{ {
bool d[6]{}; bool d[6]{};
@ -468,7 +469,6 @@ ASL_TEST(move_assign_from_inline_incompatible_allocator)
buf2 = std::move(buf); buf2 = std::move(buf);
ASL_TEST_EXPECT(buf.size() == 0);
ASL_TEST_EXPECT(buf2.size() == 2); ASL_TEST_EXPECT(buf2.size() == 2);
ASL_TEST_EXPECT(d[0] == false); ASL_TEST_EXPECT(d[0] == false);
ASL_TEST_EXPECT(d[1] == false); ASL_TEST_EXPECT(d[1] == false);

View File

@ -5,6 +5,7 @@
#include "asl/testing/testing.hpp" #include "asl/testing/testing.hpp"
#include "asl/containers/hash_map.hpp" #include "asl/containers/hash_map.hpp"
// NOLINTNEXTLINE(*-complexity)
ASL_TEST(default) ASL_TEST(default)
{ {
asl::hash_map<int, int> map; asl::hash_map<int, int> map;

View File

@ -75,7 +75,7 @@ protected:
constexpr isize_t max_size() const constexpr isize_t max_size() const
{ {
// Max load factor is 75% // 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) 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); 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_tags = static_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_values = static_cast<maybe_uninit<T>*>(m_allocator.alloc(layout::array<maybe_uninit<T>>(new_capacity)));
asl::memzero(new_tags, new_capacity); asl::memzero(new_tags, new_capacity);
isize_t new_size = 0; isize_t new_size = 0;
@ -228,7 +228,6 @@ protected:
result.tag = static_cast<uint8_t>(hash & kHashMask) | kHasValue; result.tag = static_cast<uint8_t>(hash & kHashMask) | kHasValue;
// NOLINTBEGIN(*-pointer-arithmetic) // NOLINTBEGIN(*-pointer-arithmetic)
for ( for (
isize_t i = starting_index; isize_t i = starting_index;
i != starting_index || result.first_available_index < 0; i != starting_index || result.first_available_index < 0;

View File

@ -10,7 +10,7 @@
ASL_TEST(empty) ASL_TEST(empty)
{ {
asl::hash_set<int> set; const asl::hash_set<int> set;
ASL_TEST_EXPECT(set.size() == 0); ASL_TEST_EXPECT(set.size() == 0);
@ -42,7 +42,7 @@ ASL_TEST(a_bunch_of_ints)
{ {
asl::hash_set<int> set; asl::hash_set<int> set;
int count = 3000; const int count = 3000;
for (int i = 0; i < count; ++i) for (int i = 0; i < count; ++i)
{ {
@ -98,6 +98,7 @@ struct CustomHasher
} }
}; };
// NOLINTNEXTLINE(*-complexity)
ASL_TEST(destructor_and_remove) ASL_TEST(destructor_and_remove)
{ {
static constexpr int kCount = 200; static constexpr int kCount = 200;
@ -113,9 +114,9 @@ ASL_TEST(destructor_and_remove)
ASL_TEST_EXPECT(set.size() == kCount); 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) 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); set1.insert(i);
} }
asl::hash_set<int> set2 = set1; const asl::hash_set<int> set2 = set1;
asl::hash_set<int> set3; asl::hash_set<int> set3;
set3 = set1; set3 = set1;

View File

@ -188,5 +188,5 @@ public:
} }
}; };
} } // namespace asl

View File

@ -23,6 +23,7 @@ ASL_TEST(empty_list)
ASL_TEST_EXPECT(list.back() == nullptr); ASL_TEST_EXPECT(list.back() == nullptr);
} }
// NOLINTNEXTLINE(*-complexity)
ASL_TEST(push_front) ASL_TEST(push_front)
{ {
IntNode one{1}; IntNode one{1};
@ -75,6 +76,7 @@ ASL_TEST(push_front)
ASL_TEST_ASSERT(it == end); ASL_TEST_ASSERT(it == end);
} }
// NOLINTNEXTLINE(*-complexity)
ASL_TEST(push_back) ASL_TEST(push_back)
{ {
IntNode one{1}; IntNode one{1};

View File

@ -151,7 +151,7 @@ asl::string_view asl::format_uint64(uint64_t v, asl::span<char, kMaxUint64Digits
while (v >= 100) while (v >= 100)
{ {
uint64_t x = v % 100; const uint64_t x = v % 100;
v /= 100; v /= 100;
write_two(s_pairs.subspan(static_cast<isize_t>(x * 2)).first<2>()); 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) if (v < 0)
{ {
f.write("-"); 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); AslFormat(f, absolute_value);
} }
else else

View File

@ -25,12 +25,12 @@ static constexpr char kZeros[kZeroCount] = {
static constexpr bool is_zero(float x) 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) 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> 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("-"); } if (decimal.is_negative) { f.write("-"); }
char buffer[20]; 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) if (decimal.exponent >= 0)
{ {
f.write(digits); f.write(digits);
while (decimal.exponent > 0) while (decimal.exponent > 0)
{ {
isize_t to_write = asl::min(static_cast<isize_t>(decimal.exponent), kZeroCount); const isize_t to_write = asl::min(static_cast<isize_t>(decimal.exponent), kZeroCount);
f.write(asl::string_view(kZeros, to_write)); f.write(asl::string_view(static_cast<const char*>(kZeros), to_write));
decimal.exponent -= 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()); decimal.exponent = -decimal.exponent - static_cast<int>(digits.size());
while (decimal.exponent > 0) while (decimal.exponent > 0)
{ {
isize_t to_write = asl::min(static_cast<isize_t>(decimal.exponent), kZeroCount); const isize_t to_write = asl::min(static_cast<isize_t>(decimal.exponent), kZeroCount);
f.write(asl::string_view(kZeros, to_write)); f.write(asl::string_view(static_cast<const char*>(kZeros), to_write));
decimal.exponent -= to_write; decimal.exponent -= to_write;
} }
f.write(digits); f.write(digits);

View File

@ -80,7 +80,7 @@ struct HashState
{ {
auto bytes = as_bytes(s); auto bytes = as_bytes(s);
auto hashed = city_hash::CityHash128WithSeed( 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()), static_cast<size_t>(bytes.size()),
h.state); h.state);
return HashState{hashed}; return HashState{hashed};

View File

@ -29,10 +29,10 @@ static_assert(asl::hashable<int64_t>);
ASL_TEST(integers) ASL_TEST(integers)
{ {
uint64_t a = asl::hash_value<uint16_t>(45); const uint64_t a = asl::hash_value<uint16_t>(45);
uint64_t b = asl::hash_value<uint16_t>(45); const uint64_t b = asl::hash_value<uint16_t>(45);
uint64_t c = asl::hash_value<uint16_t>(46); const uint64_t c = asl::hash_value<uint16_t>(46);
uint64_t d = asl::hash_value<uint32_t>(45); const uint64_t d = asl::hash_value<uint32_t>(45);
ASL_TEST_EXPECT(a == b); ASL_TEST_EXPECT(a == b);
ASL_TEST_EXPECT(a != c); ASL_TEST_EXPECT(a != c);
@ -187,19 +187,19 @@ static_assert(asl::uniquely_represented<asl::option<NonZero>>);
ASL_TEST(option) ASL_TEST(option)
{ {
asl::option<int> int1 = 0; const asl::option<int> int1 = 0;
asl::option<int> int2 = 0; const asl::option<int> int2 = 0;
asl::option<int> int3 = 1; const asl::option<int> int3 = 1;
asl::option<int> int4 = asl::nullopt; 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(int2));
ASL_TEST_EXPECT(asl::hash_value(int1) != asl::hash_value(int3)); ASL_TEST_EXPECT(asl::hash_value(int1) != asl::hash_value(int3));
ASL_TEST_EXPECT(asl::hash_value(int1) != asl::hash_value(int4)); ASL_TEST_EXPECT(asl::hash_value(int1) != asl::hash_value(int4));
asl::option<NonZero> noz1{8}; const asl::option<NonZero> noz1{8};
asl::option<NonZero> noz2{8}; const asl::option<NonZero> noz2{8};
asl::option<NonZero> noz3{9}; const asl::option<NonZero> noz3{9};
asl::option<NonZero> noz4 = asl::nullopt; 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(noz2));
ASL_TEST_EXPECT(asl::hash_value(noz1) != asl::hash_value(noz3)); ASL_TEST_EXPECT(asl::hash_value(noz1) != asl::hash_value(noz3));
@ -208,17 +208,18 @@ ASL_TEST(option)
static_assert(asl::hashable<asl::status>); static_assert(asl::hashable<asl::status>);
// NOLINTNEXTLINE(*-cognitive-complexity)
ASL_TEST(status) ASL_TEST(status)
{ {
asl::status s1 = asl::ok(); const asl::status s1 = asl::ok();
asl::status s2 = asl::ok(); const asl::status s2 = asl::ok();
asl::status s3 = asl::internal_error(); const asl::status s3 = asl::internal_error();
asl::status s4 = asl::internal_error(); const asl::status s4 = asl::internal_error();
asl::status s5 = asl::runtime_error(); const asl::status s5 = asl::runtime_error();
asl::status s6 = asl::internal_error("Oh, no!"); const asl::status s6 = asl::internal_error("Oh, no!");
asl::status s7 = asl::internal_error("Oh, no!"); const asl::status s7 = asl::internal_error("Oh, no!");
asl::status s8 = asl::internal_error("Oh, no"); const asl::status s8 = asl::internal_error("Oh, no");
asl::status s9 = asl::runtime_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(s1) == asl::hash_value(s2));
ASL_TEST_EXPECT(asl::hash_value(s3) == asl::hash_value(s4)); 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_TEST(status_or)
{ {
asl::status_or<int> s1 = 42; const asl::status_or<int> s1 = 42;
asl::status_or<int> s2 = 42; const asl::status_or<int> s2 = 42;
asl::status_or<int> s3 = 43; const asl::status_or<int> s3 = 43;
asl::status_or<int> s4 = asl::runtime_error(); const asl::status_or<int> s4 = asl::runtime_error();
asl::status_or<int> s5 = asl::runtime_error(); const asl::status_or<int> s5 = asl::runtime_error();
asl::status_or<int> s6 = asl::runtime_error("Hello"); const asl::status_or<int> s6 = asl::runtime_error("Hello");
asl::status_or<int> s7 = 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(s1) == asl::hash_value(s2));
ASL_TEST_EXPECT(asl::hash_value(s4) == asl::hash_value(s5)); ASL_TEST_EXPECT(asl::hash_value(s4) == asl::hash_value(s5));

View File

@ -18,7 +18,7 @@ public:
void write(asl::span<const asl::byte> s) override 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);
} }
}; };

View File

@ -26,7 +26,7 @@ public:
constexpr string() requires default_constructible<Allocator> = default; constexpr string() requires default_constructible<Allocator> = default;
explicit constexpr string(Allocator allocator) : m_buffer{std::move(allocator)} {} explicit constexpr string(Allocator allocator) : m_buffer{std::move(allocator)} {}
// NOLINTNEXTLINE(*-explicit-conversions) // NOLINTNEXTLINE(*explicit*)
constexpr string(string_view sv) constexpr string(string_view sv)
requires default_constructible<Allocator> requires default_constructible<Allocator>
: m_buffer{sv.as_span()} : m_buffer{sv.as_span()}
@ -44,16 +44,16 @@ public:
constexpr string& operator=(const string&) requires copy_assignable<Allocator> = default; constexpr string& operator=(const string&) requires copy_assignable<Allocator> = default;
constexpr string& operator=(string&&) = default; constexpr string& operator=(string&&) = default;
constexpr isize_t size() const { return m_buffer.size(); } [[nodiscard]] constexpr isize_t size() const { return m_buffer.size(); }
constexpr const char* data() const { return m_buffer.data(); } [[nodiscard]] constexpr const char* data() const { return m_buffer.data(); }
// NOLINTNEXTLINE(*-explicit-conversions) // NOLINTNEXTLINE(*explicit*)
constexpr operator string_view() const constexpr operator string_view() const
{ {
return as_string_view(); 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(); auto span = m_buffer.as_span();
return string_view{span.data(), span.size()}; return string_view{span.data(), span.size()};

View File

@ -14,13 +14,13 @@ ASL_TEST(string_builder)
ASL_TEST_EXPECT(b.as_string_view() == "abcdefg"); 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_EXPECT(s == "abcdefg");
} }
ASL_TEST(string_builder_rvalue) 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"); ASL_TEST_EXPECT(s == "abcdefg");
} }

View File

@ -8,7 +8,7 @@
ASL_TEST(default) ASL_TEST(default)
{ {
asl::string s; const asl::string s;
ASL_TEST_ASSERT(s.size() == 0); ASL_TEST_ASSERT(s.size() == 0);
ASL_TEST_ASSERT(s.as_string_view().size() == 0); ASL_TEST_ASSERT(s.as_string_view().size() == 0);
ASL_TEST_ASSERT(s == ""_sv); ASL_TEST_ASSERT(s == ""_sv);
@ -17,7 +17,7 @@ ASL_TEST(default)
ASL_TEST(from_string_view) 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.size() == 5);
ASL_TEST_ASSERT(s == "hello"_sv); ASL_TEST_ASSERT(s == "hello"_sv);
} }

View File

@ -10,20 +10,20 @@ static_assert(asl::trivially_copy_constructible<asl::string_view>);
ASL_TEST(default) ASL_TEST(default)
{ {
asl::string_view s1; const asl::string_view s1;
ASL_TEST_EXPECT(s1.is_empty()); 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_EXPECT(s2.is_empty());
} }
ASL_TEST(from_literal) 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_ASSERT(s1.size() == 5);
ASL_TEST_EXPECT(asl::memcmp(s1.data(), "Hello", 5) == 0); 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()); ASL_TEST_EXPECT(s2.is_empty());
} }
@ -47,7 +47,7 @@ ASL_TEST(from_zstr)
ASL_TEST(substr1) ASL_TEST(substr1)
{ {
asl::string_view s1 = "abcd"; const asl::string_view s1 = "abcd";
asl::string_view s2 = s1.substr(0); asl::string_view s2 = s1.substr(0);
ASL_TEST_ASSERT(s2.size() == 4); ASL_TEST_ASSERT(s2.size() == 4);
@ -63,7 +63,7 @@ ASL_TEST(substr1)
ASL_TEST(substr2) ASL_TEST(substr2)
{ {
asl::string_view s1 = "abcd"; const asl::string_view s1 = "abcd";
asl::string_view s2 = s1.substr(0, 4); asl::string_view s2 = s1.substr(0, 4);
ASL_TEST_ASSERT(s2.size() == 4); ASL_TEST_ASSERT(s2.size() == 4);
@ -82,7 +82,7 @@ ASL_TEST(substr2)
ASL_TEST(first) ASL_TEST(first)
{ {
asl::string_view s1 = "abcd"; const asl::string_view s1 = "abcd";
asl::string_view s2 = s1.first(0); asl::string_view s2 = s1.first(0);
ASL_TEST_ASSERT(s2.size() == 0); ASL_TEST_ASSERT(s2.size() == 0);
@ -98,7 +98,7 @@ ASL_TEST(first)
ASL_TEST(last) ASL_TEST(last)
{ {
asl::string_view s1 = "abcd"; const asl::string_view s1 = "abcd";
asl::string_view s2 = s1.last(0); asl::string_view s2 = s1.last(0);
ASL_TEST_ASSERT(s2.size() == 0); ASL_TEST_ASSERT(s2.size() == 0);

View File

@ -81,7 +81,7 @@ ASL_TEST(niche)
ASL_TEST_EXPECT(destroyed); ASL_TEST_EXPECT(destroyed);
} }
class Base class Base // NOLINT
{ {
public: public:
virtual ~Base() = default; virtual ~Base() = default;

View File

@ -99,8 +99,8 @@ static_assert(!asl::trivially_move_assignable<asl::option<MoveableOnly>>);
ASL_TEST(make_null) ASL_TEST(make_null)
{ {
asl::option<int> a; const asl::option<int> a;
asl::option<int> b = asl::nullopt; const asl::option<int> b = asl::nullopt;
ASL_TEST_EXPECT(!a.has_value()); ASL_TEST_EXPECT(!a.has_value());
ASL_TEST_EXPECT(!b.has_value()); ASL_TEST_EXPECT(!b.has_value());
@ -108,7 +108,7 @@ ASL_TEST(make_null)
ASL_TEST(make_value) ASL_TEST(make_value)
{ {
asl::option<int> a = 48; const asl::option<int> a = 48;
ASL_TEST_EXPECT(a.has_value()); ASL_TEST_EXPECT(a.has_value());
} }
@ -132,7 +132,7 @@ ASL_TEST(call_destructor)
asl::option<DestructorObserver> opt(std::move(obs)); asl::option<DestructorObserver> opt(std::move(obs));
ASL_TEST_EXPECT(!destroyed); ASL_TEST_EXPECT(!destroyed);
asl::option<DestructorObserver> opt2 = std::move(opt); const asl::option<DestructorObserver> opt2 = std::move(opt);
ASL_TEST_EXPECT(!destroyed); ASL_TEST_EXPECT(!destroyed);
} }
@ -213,7 +213,7 @@ ASL_TEST(convert_move)
ASL_TEST_ASSERT(opt16.has_value()); ASL_TEST_ASSERT(opt16.has_value());
ASL_TEST_EXPECT(opt16.value() == 8); ASL_TEST_EXPECT(opt16.value() == 8);
opt8 = std::move(uint8_t{10}); opt8 = uint8_t{10};
ASL_TEST_ASSERT(opt8.has_value()); ASL_TEST_ASSERT(opt8.has_value());
ASL_TEST_EXPECT(opt8.value() == 10); ASL_TEST_EXPECT(opt8.value() == 10);
@ -227,8 +227,8 @@ ASL_TEST(convert_move)
ASL_TEST(value_or) ASL_TEST(value_or)
{ {
asl::option<int> a = asl::nullopt; const asl::option<int> a = asl::nullopt;
asl::option<int> b = 2; const asl::option<int> b = 2;
ASL_TEST_EXPECT(a.value_or(5) == 5); ASL_TEST_EXPECT(a.value_or(5) == 5);
ASL_TEST_EXPECT(b.value_or(5) == 2); ASL_TEST_EXPECT(b.value_or(5) == 2);
@ -296,8 +296,8 @@ ASL_TEST(transform)
ASL_TEST(or_else) ASL_TEST(or_else)
{ {
asl::option<int> a = 5; const asl::option<int> a = 5;
asl::option<int> b; const asl::option<int> b;
auto fn = []() -> asl::option<int> { return 12; }; auto fn = []() -> asl::option<int> { return 12; };

View File

@ -17,7 +17,7 @@ static_assert(asl::size_of<asl::span<int, 2>> == asl::size_of<void*>);
ASL_TEST(empty_dynamic) ASL_TEST(empty_dynamic)
{ {
asl::span<int> s; const asl::span<int> s;
ASL_TEST_EXPECT(s.size() == 0); ASL_TEST_EXPECT(s.size() == 0);
ASL_TEST_EXPECT(s.size_bytes() == 0); ASL_TEST_EXPECT(s.size_bytes() == 0);
ASL_TEST_EXPECT(s.is_empty()); ASL_TEST_EXPECT(s.is_empty());
@ -26,7 +26,7 @@ ASL_TEST(empty_dynamic)
ASL_TEST(empty_static) ASL_TEST(empty_static)
{ {
asl::span<int, 0> s; const asl::span<int, 0> s;
ASL_TEST_EXPECT(s.size() == 0); ASL_TEST_EXPECT(s.size() == 0);
ASL_TEST_EXPECT(s.size_bytes() == 0); ASL_TEST_EXPECT(s.size_bytes() == 0);
ASL_TEST_EXPECT(s.is_empty()); ASL_TEST_EXPECT(s.is_empty());
@ -35,7 +35,7 @@ ASL_TEST(empty_static)
ASL_TEST(from_array_dynamic) ASL_TEST(from_array_dynamic)
{ {
int array[] = {1, 2, 3}; int array[] = {1, 2, 3};
asl::span<int> span = array; const asl::span<int> span = array;
ASL_TEST_ASSERT(span.size() == 3); ASL_TEST_ASSERT(span.size() == 3);
ASL_TEST_EXPECT(span[0] == 1); ASL_TEST_EXPECT(span[0] == 1);
ASL_TEST_EXPECT(span[1] == 2); ASL_TEST_EXPECT(span[1] == 2);
@ -56,7 +56,7 @@ static_assert(!asl::constructible_from<asl::span<int32_t, 8>, int32_t(&)[10]>);
ASL_TEST(from_array_static) ASL_TEST(from_array_static)
{ {
int array[] = {1, 2, 3}; int array[] = {1, 2, 3};
asl::span<int, 3> span = array; const asl::span<int, 3> span = array;
ASL_TEST_ASSERT(span.size() == 3); ASL_TEST_ASSERT(span.size() == 3);
ASL_TEST_EXPECT(span[0] == 1); ASL_TEST_EXPECT(span[0] == 1);
ASL_TEST_EXPECT(span[1] == 2); ASL_TEST_EXPECT(span[1] == 2);
@ -77,21 +77,21 @@ ASL_TEST(conversion)
{ {
int array[] = {1, 2, 3}; int array[] = {1, 2, 3};
asl::span<int> span1 = array; const asl::span<int> span1 = array;
asl::span<int, 3> span2{span1}; const asl::span<int, 3> span2{span1};
ASL_TEST_ASSERT(span2.size() == 3); ASL_TEST_ASSERT(span2.size() == 3);
ASL_TEST_EXPECT(span2[0] == 1); ASL_TEST_EXPECT(span2[0] == 1);
ASL_TEST_EXPECT(span2[1] == 2); ASL_TEST_EXPECT(span2[1] == 2);
ASL_TEST_EXPECT(span2[2] == 3); ASL_TEST_EXPECT(span2[2] == 3);
asl::span<int> span3 = span2; const asl::span<int> span3 = span2;
ASL_TEST_ASSERT(span3.size() == 3); ASL_TEST_ASSERT(span3.size() == 3);
ASL_TEST_EXPECT(span3[0] == 1); ASL_TEST_EXPECT(span3[0] == 1);
ASL_TEST_EXPECT(span3[1] == 2); ASL_TEST_EXPECT(span3[1] == 2);
ASL_TEST_EXPECT(span3[2] == 3); ASL_TEST_EXPECT(span3[2] == 3);
asl::span<const int, 3> span4{span2}; const asl::span<const int, 3> span4{span2};
ASL_TEST_ASSERT(span4.size() == 3); ASL_TEST_ASSERT(span4.size() == 3);
ASL_TEST_EXPECT(span4[0] == 1); ASL_TEST_EXPECT(span4[0] == 1);
ASL_TEST_EXPECT(span4[1] == 2); ASL_TEST_EXPECT(span4[1] == 2);
@ -138,7 +138,7 @@ static_assert(!IsValidSubspan<asl::span<int, 4>, 2, 3>);
ASL_TEST(subspan_static_from_static) ASL_TEST(subspan_static_from_static)
{ {
int array[] = {1, 2, 3, 4}; int array[] = {1, 2, 3, 4};
asl::span<int, 4> span{array}; const asl::span<int, 4> span{array};
auto s1 = span.subspan<0>(); auto s1 = span.subspan<0>();
ASL_TEST_ASSERT(s1.size() == 4); ASL_TEST_ASSERT(s1.size() == 4);
@ -164,7 +164,7 @@ ASL_TEST(subspan_static_from_static)
ASL_TEST(subspan_static_from_dynamic) ASL_TEST(subspan_static_from_dynamic)
{ {
int array[] = {1, 2, 3, 4}; int array[] = {1, 2, 3, 4};
asl::span<int> span{array}; const asl::span<int> span{array};
auto s1 = span.subspan<0>(); auto s1 = span.subspan<0>();
ASL_TEST_ASSERT(s1.size() == 4); ASL_TEST_ASSERT(s1.size() == 4);
@ -190,7 +190,7 @@ ASL_TEST(subspan_static_from_dynamic)
ASL_TEST(subspan_dynamic) ASL_TEST(subspan_dynamic)
{ {
int array[] = {1, 2, 3, 4}; int array[] = {1, 2, 3, 4};
asl::span<int> span{array}; const asl::span<int> span{array};
auto s1 = span.subspan(0); auto s1 = span.subspan(0);
ASL_TEST_ASSERT(s1.size() == 4); ASL_TEST_ASSERT(s1.size() == 4);
@ -249,7 +249,7 @@ static_assert(!IsValidFirst<asl::span<int, 4>, asl::dynamic_size>);
ASL_TEST(first_static_from_static) ASL_TEST(first_static_from_static)
{ {
int array[] = {1, 2, 3, 4}; int array[] = {1, 2, 3, 4};
asl::span<int, 4> span{array}; const asl::span<int, 4> span{array};
auto s1 = span.first<0>(); auto s1 = span.first<0>();
ASL_TEST_ASSERT(s1.size() == 0); ASL_TEST_ASSERT(s1.size() == 0);
@ -270,7 +270,7 @@ ASL_TEST(first_static_from_static)
ASL_TEST(first_static_from_dynamic) ASL_TEST(first_static_from_dynamic)
{ {
int array[] = {1, 2, 3, 4}; int array[] = {1, 2, 3, 4};
asl::span<int> span{array}; const asl::span<int> span{array};
auto s1 = span.first<0>(); auto s1 = span.first<0>();
ASL_TEST_ASSERT(s1.size() == 0); ASL_TEST_ASSERT(s1.size() == 0);
@ -291,7 +291,7 @@ ASL_TEST(first_static_from_dynamic)
ASL_TEST(first_dynamic) ASL_TEST(first_dynamic)
{ {
int array[] = {1, 2, 3, 4}; int array[] = {1, 2, 3, 4};
asl::span<int> span{array}; const asl::span<int> span{array};
auto s1 = span.first(0); auto s1 = span.first(0);
ASL_TEST_ASSERT(s1.size() == 0); ASL_TEST_ASSERT(s1.size() == 0);
@ -345,7 +345,7 @@ static_assert(!IsValidLast<asl::span<int, 4>, asl::dynamic_size>);
ASL_TEST(last_static_from_static) ASL_TEST(last_static_from_static)
{ {
int array[] = {1, 2, 3, 4}; int array[] = {1, 2, 3, 4};
asl::span<int, 4> span{array}; const asl::span<int, 4> span{array};
auto s1 = span.last<0>(); auto s1 = span.last<0>();
ASL_TEST_ASSERT(s1.size() == 0); ASL_TEST_ASSERT(s1.size() == 0);
@ -366,7 +366,7 @@ ASL_TEST(last_static_from_static)
ASL_TEST(last_static_from_dynamic) ASL_TEST(last_static_from_dynamic)
{ {
int array[] = {1, 2, 3, 4}; int array[] = {1, 2, 3, 4};
asl::span<int> span{array}; const asl::span<int> span{array};
auto s1 = span.last<0>(); auto s1 = span.last<0>();
ASL_TEST_ASSERT(s1.size() == 0); ASL_TEST_ASSERT(s1.size() == 0);
@ -387,7 +387,7 @@ ASL_TEST(last_static_from_dynamic)
ASL_TEST(last_dynamic) ASL_TEST(last_dynamic)
{ {
int array[] = {1, 2, 3, 4}; int array[] = {1, 2, 3, 4};
asl::span<int> span{array}; const asl::span<int> span{array};
auto s1 = span.last(0); auto s1 = span.last(0);
ASL_TEST_ASSERT(s1.size() == 0); ASL_TEST_ASSERT(s1.size() == 0);
@ -416,8 +416,8 @@ static_assert(HasAsMutableBytes<const int*>);
ASL_TEST(as_bytes) ASL_TEST(as_bytes)
{ {
uint32_t data[] = {0x01020304, 0x05060708}; uint32_t data[] = {0x01020304, 0x05060708};
asl::span s1(data); const asl::span s1(data);
asl::span s2 = asl::as_bytes(s1); const asl::span s2 = asl::as_bytes(s1);
ASL_TEST_ASSERT(s2.size() == 8); ASL_TEST_ASSERT(s2.size() == 8);
ASL_TEST_ASSERT(static_cast<int>(s2[0]) == 0x04); ASL_TEST_ASSERT(static_cast<int>(s2[0]) == 0x04);
@ -433,8 +433,8 @@ ASL_TEST(as_bytes)
ASL_TEST(as_mutable_bytes) ASL_TEST(as_mutable_bytes)
{ {
uint32_t data[] = {0x01020304, 0x05060708}; uint32_t data[] = {0x01020304, 0x05060708};
asl::span s1(data); const asl::span s1(data);
asl::span s2 = asl::as_mutable_bytes(s1); const asl::span s2 = asl::as_mutable_bytes(s1);
ASL_TEST_ASSERT(s2.size() == 8); ASL_TEST_ASSERT(s2.size() == 8);
ASL_TEST_ASSERT(static_cast<int>(s2[0]) == 0x04); ASL_TEST_ASSERT(static_cast<int>(s2[0]) == 0x04);

View File

@ -11,6 +11,8 @@
// @Todo Use custom allocator // @Todo Use custom allocator
using Allocator = asl::DefaultAllocator; using Allocator = asl::DefaultAllocator;
// NOLINTNEXTLINE(*-non-const-global-variables)
static Allocator g_allocator{}; static Allocator g_allocator{};
namespace namespace
@ -47,18 +49,21 @@ asl::status::status(status_code code, string_view fmt, span<format_internals::ty
asl::status_code asl::status::code_internal() const asl::status_code asl::status::code_internal() const
{ {
ASL_ASSERT(!is_inline()); ASL_ASSERT(!is_inline());
// NOLINTNEXTLINE(*-reinterpret-cast)
return reinterpret_cast<const StatusInternal*>(m_payload)->code; return reinterpret_cast<const StatusInternal*>(m_payload)->code;
} }
asl::string_view asl::status::message_internal() const asl::string_view asl::status::message_internal() const
{ {
ASL_ASSERT(!is_inline()); ASL_ASSERT(!is_inline());
// NOLINTNEXTLINE(*-reinterpret-cast)
return reinterpret_cast<const StatusInternal*>(m_payload)->msg; return reinterpret_cast<const StatusInternal*>(m_payload)->msg;
} }
void asl::status::ref() void asl::status::ref()
{ {
ASL_ASSERT(!is_inline()); ASL_ASSERT(!is_inline());
// NOLINTNEXTLINE(*-reinterpret-cast)
auto* internal = reinterpret_cast<StatusInternal*>(m_payload); auto* internal = reinterpret_cast<StatusInternal*>(m_payload);
atomic_fetch_increment(&internal->ref_count, memory_order::relaxed); atomic_fetch_increment(&internal->ref_count, memory_order::relaxed);
} }
@ -66,6 +71,7 @@ void asl::status::ref()
void asl::status::unref() void asl::status::unref()
{ {
ASL_ASSERT(!is_inline()); ASL_ASSERT(!is_inline());
// NOLINTNEXTLINE(*-reinterpret-cast)
auto* internal = reinterpret_cast<StatusInternal*>(m_payload); auto* internal = reinterpret_cast<StatusInternal*>(m_payload);
if (atomic_fetch_decrement(&internal->ref_count, memory_order::release) == 1) if (atomic_fetch_decrement(&internal->ref_count, memory_order::release) == 1)
{ {

View File

@ -20,24 +20,24 @@ static_assert(!asl::moveable<asl::status_or<Pinned>>);
ASL_TEST(ok) ASL_TEST(ok)
{ {
asl::status_or<int> s = 6; const asl::status_or<int> s = 6;
ASL_TEST_EXPECT(s.ok()); ASL_TEST_EXPECT(s.ok());
ASL_TEST_EXPECT(s.code() == asl::status_code::ok); ASL_TEST_EXPECT(s.code() == asl::status_code::ok);
} }
ASL_TEST(from_status) ASL_TEST(from_status)
{ {
asl::status_or<char> s = asl::internal_error(); const asl::status_or<char> s = asl::internal_error();
ASL_TEST_EXPECT(!s.ok()); ASL_TEST_EXPECT(!s.ok());
ASL_TEST_EXPECT(s.code() == asl::status_code::internal); ASL_TEST_EXPECT(s.code() == asl::status_code::internal);
ASL_TEST_EXPECT(s.message() == ""_sv); ASL_TEST_EXPECT(s.message() == ""_sv);
asl::status_or<int> s2 = asl::internal_error("oh no"); const asl::status_or<int> s2 = asl::internal_error("oh no");
ASL_TEST_EXPECT(!s2.ok()); ASL_TEST_EXPECT(!s2.ok());
ASL_TEST_EXPECT(s2.code() == asl::status_code::internal); ASL_TEST_EXPECT(s2.code() == asl::status_code::internal);
ASL_TEST_EXPECT(s2.message() == "oh no"_sv); ASL_TEST_EXPECT(s2.message() == "oh no"_sv);
asl::status_or<int> s3 = asl::internal_error("{} {}", 1, 2); const asl::status_or<int> s3 = asl::internal_error("{} {}", 1, 2);
ASL_TEST_EXPECT(!s3.ok()); ASL_TEST_EXPECT(!s3.ok());
ASL_TEST_EXPECT(s3.code() == asl::status_code::internal); ASL_TEST_EXPECT(s3.code() == asl::status_code::internal);
ASL_TEST_EXPECT(s3.message() == "1 2"_sv); ASL_TEST_EXPECT(s3.message() == "1 2"_sv);
@ -53,7 +53,7 @@ ASL_TEST(destructor)
ASL_TEST_EXPECT(!d); ASL_TEST_EXPECT(!d);
asl::status_or s2 = std::move(s); asl::status_or s2 = std::move(s);
ASL_TEST_EXPECT(s.ok()); ASL_TEST_EXPECT(s2.ok());
ASL_TEST_EXPECT(!d); ASL_TEST_EXPECT(!d);
s = std::move(s2); s = std::move(s2);
@ -79,8 +79,8 @@ ASL_TEST(copy)
ASL_TEST(value_or) ASL_TEST(value_or)
{ {
asl::status_or<int> s = 7; const asl::status_or<int> s = 7;
asl::status_or<int> s2 = asl::internal_error(); const asl::status_or<int> s2 = asl::internal_error();
ASL_TEST_EXPECT(s.value_or(45) == 7); ASL_TEST_EXPECT(s.value_or(45) == 7);
ASL_TEST_EXPECT(s2.value_or(45) == 45); ASL_TEST_EXPECT(s2.value_or(45) == 45);

View File

@ -9,14 +9,14 @@
ASL_TEST(simple_ok) ASL_TEST(simple_ok)
{ {
asl::status s = asl::ok(); const asl::status s = asl::ok();
ASL_TEST_ASSERT(s.ok()); ASL_TEST_ASSERT(s.ok());
ASL_TEST_ASSERT(s.code() == asl::status_code::ok); ASL_TEST_ASSERT(s.code() == asl::status_code::ok);
} }
ASL_TEST(simple_code) ASL_TEST(simple_code)
{ {
asl::status s = asl::runtime_error(); const asl::status s = asl::runtime_error();
ASL_TEST_ASSERT(!s.ok()); ASL_TEST_ASSERT(!s.ok());
ASL_TEST_ASSERT(s.code() == asl::status_code::runtime); ASL_TEST_ASSERT(s.code() == asl::status_code::runtime);
ASL_TEST_ASSERT(s.message() == ""_sv); ASL_TEST_ASSERT(s.message() == ""_sv);
@ -24,7 +24,7 @@ ASL_TEST(simple_code)
ASL_TEST(with_message) ASL_TEST(with_message)
{ {
asl::status s = asl::internal_error("We done goofed"); const asl::status s = asl::internal_error("We done goofed");
ASL_TEST_ASSERT(!s.ok()); ASL_TEST_ASSERT(!s.ok());
ASL_TEST_ASSERT(s.code() == asl::status_code::internal); ASL_TEST_ASSERT(s.code() == asl::status_code::internal);
ASL_TEST_ASSERT(s.message() == "We done goofed"_sv); ASL_TEST_ASSERT(s.message() == "We done goofed"_sv);
@ -32,8 +32,8 @@ ASL_TEST(with_message)
ASL_TEST(copy_inline) ASL_TEST(copy_inline)
{ {
asl::status s = asl::ok(); const asl::status s = asl::ok();
asl::status s2 = asl::internal_error(); const asl::status s2 = asl::internal_error();
asl::status s3 = s; asl::status s3 = s;
ASL_TEST_ASSERT(s3.code() == asl::status_code::ok); ASL_TEST_ASSERT(s3.code() == asl::status_code::ok);
@ -47,7 +47,7 @@ ASL_TEST(copy_message)
asl::status s2 = asl::ok(); asl::status s2 = asl::ok();
{ {
asl::status s = asl::internal_error("Oh no!"); const asl::status s = asl::internal_error("Oh no!");
ASL_TEST_ASSERT(!s.ok()); ASL_TEST_ASSERT(!s.ok());
ASL_TEST_ASSERT(s.code() == asl::status_code::internal); ASL_TEST_ASSERT(s.code() == asl::status_code::internal);
ASL_TEST_ASSERT(s.message() == "Oh no!"_sv); ASL_TEST_ASSERT(s.message() == "Oh no!"_sv);

View File

@ -12,6 +12,7 @@ import time
TO_FIX = [ TO_FIX = [
".bazelrc", ".bazelrc",
".clang-tidy", ".clang-tidy",
".clangd",
".gitignore", ".gitignore",
"**/*.hpp", "**/*.hpp",
"**/*.h", "**/*.h",