aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.ucl
diff options
context:
space:
mode:
authorLexi Winter <lexi@le-fay.org>2025-06-29 17:16:22 +0100
committerLexi Winter <lexi@le-fay.org>2025-06-29 17:16:22 +0100
commit4fa6821e0645ff61a9380cd090abff472205c630 (patch)
treebd95f13b2dc0bd9692681f50c365d2914a520bfe /nihil.ucl
parente5180acf5f2dfac788e8c12886095ed1ac66fae5 (diff)
downloadnihil-4fa6821e0645ff61a9380cd090abff472205c630.tar.gz
nihil-4fa6821e0645ff61a9380cd090abff472205c630.tar.bz2
add clang-tidy support
Diffstat (limited to 'nihil.ucl')
-rw-r--r--nihil.ucl/integer.ccm2
-rw-r--r--nihil.ucl/map.ccm3
-rw-r--r--nihil.ucl/object.cc21
-rw-r--r--nihil.ucl/object.ccm2
-rw-r--r--nihil.ucl/parser.ccm2
-rw-r--r--nihil.ucl/real.ccm2
-rw-r--r--nihil.ucl/tests/map.cc16
7 files changed, 21 insertions, 27 deletions
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<std::int64_t>::max()))
throw std::out_of_range("literal out of range");
- return integer(i);
+ return integer(static_cast<std::int64_t>(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<bool, std::invoke_result<F>>)
{
auto handler = std::make_unique<macro_handler>(
- std::move(func));
+ std::forward<F>(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<long double>(std::numeric_limits<double>::min()))
throw std::out_of_range("literal out of range");
- return real(d);
+ return real(static_cast<double>(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)