Skip to content

Commit

Permalink
Fix new clang-tidy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisThrasher committed Jun 24, 2024
1 parent 261f1a0 commit dcee303
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ Checks: >
performance-*,
portability-*,
readability-*,
-bugprone-unchecked-optional-access,
-concurrency-mt-unsafe,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-macro-usage,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-misc-include-cleaner,
-misc-non-private-member-variables-in-classes,
-modernize-avoid-bind,
-modernize-use-trailing-return-type,
-readability-avoid-unconditional-preprocessor-if,
-readability-braces-around-statements,
-readability-identifier-length,
-readability-magic-numbers,
Expand Down
18 changes: 10 additions & 8 deletions tests/monad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,34 @@

using namespace std::string_literals;

static constexpr auto maybe_non_zero(int in) {
namespace {
constexpr auto maybe_non_zero(int in) {
return (in != 0) ? std::optional(in) : std::nullopt;
}

static auto maybe_lt_3_round(double in) {
auto maybe_lt_3_round(double in) {
return (in < 3) ? std::optional<int>(std::round(in)) : std::nullopt;
}

static auto unsafe_divide_4_by(double val) {
auto unsafe_divide_4_by(double val) {
if (val == 0) throw std::runtime_error("divide by zero");
return 4.0 / val;
}

template <typename T>
using Result = tl::expected<T, std::string>;

static Result<double> divide(double x, double y) {
Result<double> divide(double x, double y) {
if (y == 0) return tl::unexpected("divide by 0"s);
return x / y;
}

static Result<double> multiply(double x, double y) { return x * y; }
Result<double> multiply(double x, double y) { return x * y; }

static Result<double> divide_3(double x) { return divide(3, x); }
Result<double> divide_3(double x) { return divide(3, x); }

static Result<double> multiply_3(double x) { return multiply(3, x); }
Result<double> multiply_3(double x) { return multiply(3, x); }
}

TEST_CASE("rsl::mbind") {
SECTION("Optional value") {
Expand Down Expand Up @@ -210,7 +212,7 @@ TEST_CASE("operator|") {
auto const k = [](auto x) { return [=](auto) { return x; }; };
auto const mul = [](auto x, auto y) { return x * y; };
auto const bind1 = [](auto fn, auto x) { return [=](auto y) { return fn(x, y); }; };
auto const three = [](auto) { return int{3}; };
auto const three = [](auto) { return 3; };
auto const wrap = [](auto x) { return Result<decltype(x)>{x}; };

CHECK((int{5} | i) == 5);
Expand Down
4 changes: 3 additions & 1 deletion tests/random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

#include <thread>

static auto const* const rng = &rsl::rng({0, 1});
namespace {
auto const* const rng = &rsl::rng({0, 1});
}

TEST_CASE("rsl::rng") {
SECTION("Repeated calls in thread yield same object") {
Expand Down
2 changes: 1 addition & 1 deletion tests/static_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ TEST_CASE("rsl::StaticString") {
}

TEST_CASE("rsl::to_string") {
CHECK(rsl::to_string(rsl::StaticString<0>()) == ""s);
CHECK(rsl::to_string(rsl::StaticString<0>()).empty());
CHECK(rsl::to_string(rsl::StaticString<10>("happy"s)) == "happy"s);
}
4 changes: 3 additions & 1 deletion tests/try.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@

using ExpectedType = tl::expected<int, std::string>;

static ExpectedType check_try_macro(ExpectedType const& expected) {
namespace {
ExpectedType check_try_macro(ExpectedType const& expected) {
ExpectedType::value_type value = TRY(expected);
return ++value;
}
}

TEST_CASE("TRY") {
CHECK(check_try_macro(ExpectedType(42)) == 43);
Expand Down

0 comments on commit dcee303

Please sign in to comment.