Skip to content

Commit

Permalink
Working through clang-tidy warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhuggett committed Dec 17, 2023
1 parent bc14466 commit 0e091f2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
30 changes: 19 additions & 11 deletions include/peejay/dom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,19 @@ struct element : variant {
using variant::variant;
struct element *parent = nullptr;

element () noexcept = default;
element (element const &rhs) = delete;
element (element &&rhs) noexcept
: variant (std::move (static_cast<variant &&> (rhs))) {
adjust_parents ();
}
~element () noexcept = default;

element &operator= (element const &rhs) = delete;
element &operator= (element &&rhs) noexcept {
if (this != &rhs) {
static_cast<variant *> (this)->operator= (
std::move (static_cast<variant &&> (rhs)));
adjust_parents ();
}
return *this;
}
element &operator= (element &&rhs) noexcept;

bool operator== (element const &rhs) const;
bool operator!= (element const &rhs) const { return !operator== (rhs); }

/// Evaluate a JSON pointer (RFC6901).
element *eval_pointer (u8string_view s);
Expand All @@ -98,6 +95,17 @@ struct element : variant {
static constexpr std::optional<unsigned> stoui (u8string_view s);
};

// operator=
// ~~~~~~~~~
inline element &element::operator= (element &&rhs) noexcept {
if (this != &rhs) {
static_cast<variant *> (this)->operator= (
std::move (static_cast<variant &&> (rhs)));
adjust_parents ();
}
return *this;
}

// operator==
// ~~~~~~~~~~
inline bool element::operator== (element const &rhs) const {
Expand Down Expand Up @@ -152,7 +160,7 @@ inline std::optional<std::pair<u8string_view, unsigned>> decimal (
auto prefix = 0U;
auto pos = u8string_view::size_type{0};
auto const len = s.length ();
for (; pos < len && std::isdigit (s[pos]); ++pos) {
for (; pos < len && std::isdigit (s[pos]) != 0; ++pos) {
prefix = prefix * 10U + static_cast<unsigned> (s[pos] - '0');
}
if (pos == 0) {
Expand Down Expand Up @@ -192,7 +200,7 @@ inline std::optional<variant> element::eval_relative_pointer (u8string_view s) {
// - If the referenced value is an object member within an object, then the
// new referenced value is that object.

if (s.empty () || !std::isdigit (s.front ())) {
if (s.empty () || std::isdigit (s.front ()) == 0) {
return {};
}
auto const d1 = decimal (s);
Expand Down Expand Up @@ -345,7 +353,7 @@ constexpr std::optional<unsigned> element::stoui (u8string_view s) {
}
auto res = 0U;
for (auto const c : s) {
if (!std::isdigit (static_cast<int> (c))) {
if (std::isdigit (static_cast<int> (c)) == 0) {
return {};
}
res = res * 10U + static_cast<unsigned> (c - '0');
Expand Down
18 changes: 11 additions & 7 deletions unittests/test_small_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <gmock/gmock.h>

#include <exception>
#include <numeric>
#include <sstream>

Expand All @@ -24,7 +25,8 @@
using peejay::small_vector;
using testing::ElementsAre;

struct copy_ex : public std::domain_error {
class copy_ex : public std::domain_error {
public:
copy_ex () : std::domain_error{"copy"} {}
};
struct copy_throws {
Expand Down Expand Up @@ -76,7 +78,7 @@ struct move_throws {
move_throws () = default;
explicit move_throws (int v_) : v{v_} {}
move_throws (move_throws const&) noexcept = default;
// NOLINTNEXTLINE(bugprone-exception-escape)
// NOLINTNEXTLINE
move_throws (move_throws&& rhs) {
if (throws) {
throw move_ex{};
Expand All @@ -87,7 +89,7 @@ struct move_throws {
~move_throws () noexcept = default;

move_throws& operator= (move_throws const&) noexcept = default;
// NOLINTNEXTLINE(bugprone-exception-escape)
// NOLINTNEXTLINE
move_throws& operator= (move_throws&& rhs) {
if (&rhs != this) {
if (throws) {
Expand Down Expand Up @@ -134,7 +136,7 @@ static_assert (

// NOLINTNEXTLINE
TEST (SmallVector, DefaultCtor) {
peejay::small_vector<int, 8> b;
peejay::small_vector<int, 8> const b;
EXPECT_EQ (0U, b.size ())
<< "expected the initial size to be number number of stack elements";
EXPECT_EQ (8U, b.capacity ());
Expand Down Expand Up @@ -214,15 +216,15 @@ TEST (SmallVector, CtorInitializerList) {

// NOLINTNEXTLINE
TEST (SmallVector, CtorInitializerList2) {
peejay::small_vector<int, 2> b{1, 2, 3, 4};
peejay::small_vector<int, 2> const b{1, 2, 3, 4};
EXPECT_THAT (b, ::testing::ElementsAre (1, 2, 3, 4));
}

// NOLINTNEXTLINE
TEST (SmallVector, CtorCopy) {
peejay::small_vector<int, 3> const b{3, 5};
// NOLINTNEXTLINE(performance-unnecessary-copy-initialization)
peejay::small_vector<int, 2> c = b;
peejay::small_vector<int, 2> const c = b;
EXPECT_EQ (2U, c.size ());
EXPECT_THAT (c, ElementsAre (3, 5));
}
Expand Down Expand Up @@ -629,6 +631,7 @@ TEST (SmallVector, IteratorNonConst) {
// I populate the buffer manually here to ensure coverage of basic iterator
// operations, but use std::iota() elsewhere to keep the tests simple.
int value = 42;
// NOLINTNEXTLINE (modernize-loop-convert)
for (decltype (buffer)::iterator it = buffer.begin (), end = buffer.end ();
it != end; ++it) {
*it = value++;
Expand All @@ -637,6 +640,7 @@ TEST (SmallVector, IteratorNonConst) {
{
// Manually copy the contents of the buffer to a new vector.
std::vector<int> actual;
// NOLINTNEXTLINE (modernize-loop-convert)
for (decltype (buffer)::iterator it = buffer.begin (), end = buffer.end ();
it != end; ++it) {
actual.push_back (*it);
Expand Down Expand Up @@ -700,7 +704,7 @@ TEST (SmallVector, IteratorConstReverse) {
return buffer;
}();

std::vector<int> actual (cbuffer.rbegin (), cbuffer.rend ());
std::vector<int> const actual (cbuffer.rbegin (), cbuffer.rend ());
EXPECT_THAT (actual, ::testing::ElementsAre (45, 44, 43, 42));
}

Expand Down

0 comments on commit 0e091f2

Please sign in to comment.