diff options
author | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2025-03-07 00:00:43 +0100 |
---|---|---|
committer | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2025-03-07 00:00:43 +0100 |
commit | 636882316b5191931e144212d93665c10859ac95 (patch) | |
tree | 740f76daceee5bff223b790a4eb91f4e59c5be61 /asl/types | |
parent | f0cccbe3285c039553e1fd8b5a5c7830d6087974 (diff) |
Some work on clang-tidy-ing things up
Diffstat (limited to 'asl/types')
-rw-r--r-- | asl/types/box_tests.cpp | 2 | ||||
-rw-r--r-- | asl/types/option_tests.cpp | 18 | ||||
-rw-r--r-- | asl/types/span_tests.cpp | 42 | ||||
-rw-r--r-- | asl/types/status.cpp | 6 | ||||
-rw-r--r-- | asl/types/status_or_tests.cpp | 14 | ||||
-rw-r--r-- | asl/types/status_tests.cpp | 12 |
6 files changed, 50 insertions, 44 deletions
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/asl/types/span_tests.cpp @@ -17,7 +17,7 @@ static_assert(asl::size_of<asl::span<int, 2>> == asl::size_of<void*>); ASL_TEST(empty_dynamic) { - asl::span<int> s; + const asl::span<int> s; ASL_TEST_EXPECT(s.size() == 0); ASL_TEST_EXPECT(s.size_bytes() == 0); ASL_TEST_EXPECT(s.is_empty()); @@ -26,7 +26,7 @@ ASL_TEST(empty_dynamic) 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_bytes() == 0); ASL_TEST_EXPECT(s.is_empty()); @@ -35,7 +35,7 @@ ASL_TEST(empty_static) ASL_TEST(from_array_dynamic) { int array[] = {1, 2, 3}; - asl::span<int> span = array; + const asl::span<int> span = array; ASL_TEST_ASSERT(span.size() == 3); ASL_TEST_EXPECT(span[0] == 1); 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) { 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_EXPECT(span[0] == 1); ASL_TEST_EXPECT(span[1] == 2); @@ -77,21 +77,21 @@ ASL_TEST(conversion) { 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_EXPECT(span2[0] == 1); ASL_TEST_EXPECT(span2[1] == 2); 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_EXPECT(span3[0] == 1); ASL_TEST_EXPECT(span3[1] == 2); 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_EXPECT(span4[0] == 1); 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) { int array[] = {1, 2, 3, 4}; - asl::span<int, 4> span{array}; + const asl::span<int, 4> span{array}; auto s1 = span.subspan<0>(); ASL_TEST_ASSERT(s1.size() == 4); @@ -164,7 +164,7 @@ ASL_TEST(subspan_static_from_static) ASL_TEST(subspan_static_from_dynamic) { int array[] = {1, 2, 3, 4}; - asl::span<int> span{array}; + const asl::span<int> span{array}; auto s1 = span.subspan<0>(); ASL_TEST_ASSERT(s1.size() == 4); @@ -190,7 +190,7 @@ ASL_TEST(subspan_static_from_dynamic) ASL_TEST(subspan_dynamic) { int array[] = {1, 2, 3, 4}; - asl::span<int> span{array}; + const asl::span<int> span{array}; auto s1 = span.subspan(0); 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) { int array[] = {1, 2, 3, 4}; - asl::span<int, 4> span{array}; + const asl::span<int, 4> span{array}; auto s1 = span.first<0>(); ASL_TEST_ASSERT(s1.size() == 0); @@ -270,7 +270,7 @@ ASL_TEST(first_static_from_static) ASL_TEST(first_static_from_dynamic) { int array[] = {1, 2, 3, 4}; - asl::span<int> span{array}; + const asl::span<int> span{array}; auto s1 = span.first<0>(); ASL_TEST_ASSERT(s1.size() == 0); @@ -291,7 +291,7 @@ ASL_TEST(first_static_from_dynamic) ASL_TEST(first_dynamic) { int array[] = {1, 2, 3, 4}; - asl::span<int> span{array}; + const asl::span<int> span{array}; auto s1 = span.first(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) { int array[] = {1, 2, 3, 4}; - asl::span<int, 4> span{array}; + const asl::span<int, 4> span{array}; auto s1 = span.last<0>(); ASL_TEST_ASSERT(s1.size() == 0); @@ -366,7 +366,7 @@ ASL_TEST(last_static_from_static) ASL_TEST(last_static_from_dynamic) { int array[] = {1, 2, 3, 4}; - asl::span<int> span{array}; + const asl::span<int> span{array}; auto s1 = span.last<0>(); ASL_TEST_ASSERT(s1.size() == 0); @@ -387,7 +387,7 @@ ASL_TEST(last_static_from_dynamic) ASL_TEST(last_dynamic) { int array[] = {1, 2, 3, 4}; - asl::span<int> span{array}; + const asl::span<int> span{array}; auto s1 = span.last(0); ASL_TEST_ASSERT(s1.size() == 0); @@ -416,8 +416,8 @@ static_assert(HasAsMutableBytes<const int*>); ASL_TEST(as_bytes) { uint32_t data[] = {0x01020304, 0x05060708}; - asl::span s1(data); - asl::span s2 = asl::as_bytes(s1); + const asl::span s1(data); + const asl::span s2 = asl::as_bytes(s1); ASL_TEST_ASSERT(s2.size() == 8); ASL_TEST_ASSERT(static_cast<int>(s2[0]) == 0x04); @@ -433,8 +433,8 @@ ASL_TEST(as_bytes) ASL_TEST(as_mutable_bytes) { uint32_t data[] = {0x01020304, 0x05060708}; - asl::span s1(data); - asl::span s2 = asl::as_mutable_bytes(s1); + const asl::span s1(data); + const asl::span s2 = asl::as_mutable_bytes(s1); ASL_TEST_ASSERT(s2.size() == 8); ASL_TEST_ASSERT(static_cast<int>(s2[0]) == 0x04); diff --git a/asl/types/status.cpp b/asl/types/status.cpp index 94c4977..43f3b9e 100644 --- a/asl/types/status.cpp +++ b/asl/types/status.cpp @@ -11,6 +11,8 @@ // @Todo Use custom allocator using Allocator = asl::DefaultAllocator; + +// NOLINTNEXTLINE(*-non-const-global-variables) static Allocator g_allocator{}; 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_ASSERT(!is_inline()); + // NOLINTNEXTLINE(*-reinterpret-cast) return reinterpret_cast<const StatusInternal*>(m_payload)->code; } asl::string_view asl::status::message_internal() const { ASL_ASSERT(!is_inline()); + // NOLINTNEXTLINE(*-reinterpret-cast) return reinterpret_cast<const StatusInternal*>(m_payload)->msg; } void asl::status::ref() { ASL_ASSERT(!is_inline()); + // NOLINTNEXTLINE(*-reinterpret-cast) auto* internal = reinterpret_cast<StatusInternal*>(m_payload); atomic_fetch_increment(&internal->ref_count, memory_order::relaxed); } @@ -66,6 +71,7 @@ void asl::status::ref() void asl::status::unref() { ASL_ASSERT(!is_inline()); + // NOLINTNEXTLINE(*-reinterpret-cast) auto* internal = reinterpret_cast<StatusInternal*>(m_payload); if (atomic_fetch_decrement(&internal->ref_count, memory_order::release) == 1) { diff --git a/asl/types/status_or_tests.cpp b/asl/types/status_or_tests.cpp index 08b4a0f..1a96c80 100644 --- a/asl/types/status_or_tests.cpp +++ b/asl/types/status_or_tests.cpp @@ -20,24 +20,24 @@ static_assert(!asl::moveable<asl::status_or<Pinned>>); 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.code() == asl::status_code::ok); } 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.code() == asl::status_code::internal); 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.code() == asl::status_code::internal); 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.code() == asl::status_code::internal); ASL_TEST_EXPECT(s3.message() == "1 2"_sv); @@ -53,7 +53,7 @@ ASL_TEST(destructor) ASL_TEST_EXPECT(!d); asl::status_or s2 = std::move(s); - ASL_TEST_EXPECT(s.ok()); + ASL_TEST_EXPECT(s2.ok()); ASL_TEST_EXPECT(!d); s = std::move(s2); @@ -79,8 +79,8 @@ ASL_TEST(copy) ASL_TEST(value_or) { - asl::status_or<int> s = 7; - asl::status_or<int> s2 = asl::internal_error(); + const asl::status_or<int> s = 7; + const asl::status_or<int> s2 = asl::internal_error(); ASL_TEST_EXPECT(s.value_or(45) == 7); ASL_TEST_EXPECT(s2.value_or(45) == 45); diff --git a/asl/types/status_tests.cpp b/asl/types/status_tests.cpp index 362556d..60715f5 100644 --- a/asl/types/status_tests.cpp +++ b/asl/types/status_tests.cpp @@ -9,14 +9,14 @@ ASL_TEST(simple_ok) { - asl::status s = asl::ok(); + const asl::status s = asl::ok(); ASL_TEST_ASSERT(s.ok()); ASL_TEST_ASSERT(s.code() == asl::status_code::ok); } 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.code() == asl::status_code::runtime); ASL_TEST_ASSERT(s.message() == ""_sv); @@ -24,7 +24,7 @@ ASL_TEST(simple_code) 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.code() == asl::status_code::internal); ASL_TEST_ASSERT(s.message() == "We done goofed"_sv); @@ -32,8 +32,8 @@ ASL_TEST(with_message) ASL_TEST(copy_inline) { - asl::status s = asl::ok(); - asl::status s2 = asl::internal_error(); + const asl::status s = asl::ok(); + const asl::status s2 = asl::internal_error(); asl::status s3 = s; ASL_TEST_ASSERT(s3.code() == asl::status_code::ok); @@ -47,7 +47,7 @@ ASL_TEST(copy_message) 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.code() == asl::status_code::internal); ASL_TEST_ASSERT(s.message() == "Oh no!"_sv); |