From 4fa6821e0645ff61a9380cd090abff472205c630 Mon Sep 17 00:00:00 2001 From: Lexi Winter Date: Sun, 29 Jun 2025 17:16:22 +0100 Subject: add clang-tidy support --- nihil.ucl/integer.ccm | 2 +- nihil.ucl/map.ccm | 3 ++- nihil.ucl/object.cc | 21 ++++++--------------- nihil.ucl/object.ccm | 2 +- nihil.ucl/parser.ccm | 2 +- nihil.ucl/real.ccm | 2 +- nihil.ucl/tests/map.cc | 16 +++++++++------- 7 files changed, 21 insertions(+), 27 deletions(-) (limited to 'nihil.ucl') diff --git a/nihil.ucl/integer.ccm b/nihil.ucl/integer.ccm index 0ea490c..e35a471 100644 --- a/nihil.ucl/integer.ccm +++ b/nihil.ucl/integer.ccm @@ -81,7 +81,7 @@ export constexpr auto operator""_ucl (unsigned long long i) -> integer if (std::cmp_greater(i, std::numeric_limits::max())) throw std::out_of_range("literal out of range"); - return integer(i); + return integer(static_cast(i)); } } // namespace nihil::ucl::literals diff --git a/nihil.ucl/map.ccm b/nihil.ucl/map.ccm index 1c5dd19..fa77601 100644 --- a/nihil.ucl/map.ccm +++ b/nihil.ucl/map.ccm @@ -88,7 +88,8 @@ private: struct state { state(::ucl_object_t const *obj) { - if ((iter = ::ucl_object_iterate_new(obj)) == nullptr) + iter = ::ucl_object_iterate_new(obj); + if (iter == nullptr) throw std::system_error(make_error_code( std::errc(errno))); } diff --git a/nihil.ucl/object.cc b/nihil.ucl/object.cc index 9a150fb..53fc4c7 100644 --- a/nihil.ucl/object.cc +++ b/nihil.ucl/object.cc @@ -33,10 +33,12 @@ object::object(object &&other) noexcept : m_object(std::exchange(other.m_object, nullptr)) {} -object::object(object const &other) noexcept +object::object(object const &other) : m_object(nullptr) { - *this = other; + m_object = ::ucl_object_copy(other.get_ucl_object()); + if (m_object == nullptr) + throw std::runtime_error("failed to copy UCL object"); } auto object::operator=(this object &self, object &&other) noexcept @@ -47,20 +49,9 @@ auto object::operator=(this object &self, object &&other) noexcept return self; } -auto object::operator=(this object &self, object const &other) - -> object & +auto object::operator=(this object &self, object const &other) -> object & { - if (&self != &other) { - auto *new_uobj = ::ucl_object_copy(other.get_ucl_object()); - if (new_uobj == nullptr) - throw std::runtime_error("failed to copy UCL object"); - - if (self.m_object != nullptr) - ::ucl_object_unref(self.m_object); - self.m_object = new_uobj; - } - - return self; + return self = object(other); } auto object::ref(this object const &self) -> object diff --git a/nihil.ucl/object.ccm b/nihil.ucl/object.ccm index dffb54e..9a7eaf7 100644 --- a/nihil.ucl/object.ccm +++ b/nihil.ucl/object.ccm @@ -49,7 +49,7 @@ export struct object { // Copyable. // Note that this copies the entire UCL object. - object(object const &other) noexcept; + object(object const &other); auto operator=(this object &self, object const &other) -> object &; // Increase the refcount of this object. diff --git a/nihil.ucl/parser.ccm b/nihil.ucl/parser.ccm index 20e5c66..5fa3495 100644 --- a/nihil.ucl/parser.ccm +++ b/nihil.ucl/parser.ccm @@ -72,7 +72,7 @@ struct parser { requires (std::same_as>) { auto handler = std::make_unique( - std::move(func)); + std::forward(func)); auto cname = std::string(name); ::ucl_parser_register_macro( diff --git a/nihil.ucl/real.ccm b/nihil.ucl/real.ccm index c491553..f425a9a 100644 --- a/nihil.ucl/real.ccm +++ b/nihil.ucl/real.ccm @@ -78,7 +78,7 @@ export constexpr auto operator""_ucl (long double d) -> real d < static_cast(std::numeric_limits::min())) throw std::out_of_range("literal out of range"); - return real(d); + return real(static_cast(d)); } } // namespace nihil::ucl::literals diff --git a/nihil.ucl/tests/map.cc b/nihil.ucl/tests/map.cc index 5d2fbe1..7240cb3 100644 --- a/nihil.ucl/tests/map.cc +++ b/nihil.ucl/tests/map.cc @@ -9,6 +9,8 @@ import nihil.ucl; +//NOLINTBEGIN(bugprone-unchecked-optional-access) + TEST_CASE("ucl: map: invariants", "[ucl]") { using namespace nihil::ucl; @@ -110,11 +112,10 @@ TEST_CASE("ucl: map: find", "[ucl]") }; auto obj = map.find("42"); - REQUIRE(obj != std::nullopt); - REQUIRE(*obj == 42); + REQUIRE(obj.value() == 42); obj = map.find("43"); - REQUIRE(obj == std::nullopt); + REQUIRE(!obj.has_value()); } TEST_CASE("ucl: map: iterate", "[ucl]") @@ -179,12 +180,13 @@ TEST_CASE("ucl: map: pop", "[uc]") REQUIRE(map.find("42") != std::nullopt); auto obj = map.pop("42"); - REQUIRE(obj != std::nullopt); - REQUIRE(*obj == 42); + REQUIRE(obj.value() == 42); - REQUIRE(map.find("42") == std::nullopt); + REQUIRE(!map.find("42")); REQUIRE(map["1"] == 1); obj = map.pop("42"); - REQUIRE(obj == std::nullopt); + REQUIRE(!obj); } + +//NOLINTEND(bugprone-unchecked-optional-access) -- cgit v1.2.3