Skip to content

Commit 1ff56a8

Browse files
Merge pull request #798 from laurynas-biveinis/cppcheck-2.18-full
Fully update cppcheck support for 2.18
2 parents 2dd6d29 + 3844b24 commit 1ff56a8

11 files changed

Lines changed: 92 additions & 53 deletions

CMakeLists.txt

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -621,17 +621,8 @@ set(CPPCHECK_ARGS
621621
# False positive on Google Test TEST macro and compilers are much better
622622
# for syntax checking anyway
623623
"--suppress=syntaxError"
624-
# Likewise
625-
"--suppress=internalAstError"
626-
# False positives with conditional noexcept
627-
"--suppress=throwInNoexceptFunction"
628-
# Leave it for the compilers to diagnose
629-
"--suppress=unreadVariable"
630-
# False positives on structured bindings with 2.5
631-
"--suppress=unassignedVariable"
632-
"--suppress=unusedVariable"
633-
# Informational message that fails the build. Remove once cppcheck 2.11 is the
634-
# minimum
624+
# Non-actionable informational message that even fails the build before
625+
# cppcheck 2.11.
635626
"--suppress=normalCheckLevelMaxBranches")
636627

637628
option(CPPCHECK_AGGRESSIVE "Enable inconclusive cppcheck checks")

CMakePresets.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@
7474
"STATIC_ANALYSIS": "ON"
7575
}
7676
},
77+
{
78+
"name": "cppcheck-aggressive",
79+
"hidden": true,
80+
"cacheVariables": {
81+
"CPPCHECK_AGGRESSIVE": "ON"
82+
}
83+
},
7784
{
7885
"name": "gcc",
7986
"hidden": true,
@@ -130,6 +137,13 @@
130137
"tsan"
131138
]
132139
},
140+
{
141+
"name": "release-cppcheck-aggressive",
142+
"inherits": [
143+
"release",
144+
"cppcheck-aggressive"
145+
]
146+
},
133147
{
134148
"name": "debug",
135149
"inherits": "base-unix",
@@ -158,6 +172,13 @@
158172
"ubsan"
159173
]
160174
},
175+
{
176+
"name": "debug-cppcheck-aggressive",
177+
"inherits": [
178+
"debug",
179+
"cppcheck-aggressive"
180+
]
181+
},
161182
{
162183
"name": "gcc-release",
163184
"inherits": [
@@ -407,6 +428,11 @@
407428
"configurePreset": "release-tsan",
408429
"inherits": "base"
409430
},
431+
{
432+
"name": "release-cppcheck-aggressive",
433+
"configurePreset": "release-cppcheck-aggressive",
434+
"inherits": "base"
435+
},
410436
{
411437
"name": "debug",
412438
"configurePreset": "debug",
@@ -427,6 +453,11 @@
427453
"configurePreset": "debug-ubsan",
428454
"inherits": "base"
429455
},
456+
{
457+
"name": "debug-cppcheck-aggressive",
458+
"configurePreset": "debug-cppcheck-aggressive",
459+
"inherits": "base"
460+
},
430461
{
431462
"name": "gcc-release",
432463
"configurePreset": "gcc-release",
@@ -602,6 +633,11 @@
602633
"configurePreset": "release-tsan",
603634
"inherits": "base"
604635
},
636+
{
637+
"name": "release-cppcheck-aggressive",
638+
"configurePreset": "release-cppcheck-aggressive",
639+
"inherits": "base"
640+
},
605641
{
606642
"name": "debug",
607643
"configurePreset": "debug",
@@ -622,6 +658,11 @@
622658
"configurePreset": "debug-ubsan",
623659
"inherits": "base"
624660
},
661+
{
662+
"name": "debug-cppcheck-aggressive",
663+
"configurePreset": "debug-cppcheck-aggressive",
664+
"inherits": "base"
665+
},
625666
{
626667
"name": "gcc-release",
627668
"configurePreset": "gcc-release",

art.hpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,6 @@ class db final {
530530
return node_counts[as_i<NodeType>];
531531
}
532532

533-
// cppcheck-suppress returnByReference
534533
[[nodiscard, gnu::pure]] constexpr auto get_node_counts() const noexcept {
535534
return node_counts;
536535
}
@@ -541,7 +540,6 @@ class db final {
541540
return growing_inode_counts[internal_as_i<NodeType>];
542541
}
543542

544-
// cppcheck-suppress returnByReference
545543
[[nodiscard, gnu::pure]] constexpr auto get_growing_inode_counts()
546544
const noexcept {
547545
return growing_inode_counts;
@@ -553,7 +551,6 @@ class db final {
553551
return shrinking_inode_counts[internal_as_i<NodeType>];
554552
}
555553

556-
// cppcheck-suppress returnByReference
557554
[[nodiscard, gnu::pure]] constexpr auto get_shrinking_inode_counts()
558555
const noexcept {
559556
return shrinking_inode_counts;
@@ -919,30 +916,30 @@ typename db<Key, Value>::get_result db<Key, Value>::get_internal(
919916

920917
UNODB_DETAIL_DISABLE_MSVC_WARNING(26430)
921918
template <typename Key, typename Value>
922-
bool db<Key, Value>::insert_internal(art_key_type k, value_type v) {
919+
bool db<Key, Value>::insert_internal(art_key_type insert_key, value_type v) {
923920
if (UNODB_DETAIL_UNLIKELY(root == nullptr)) {
924-
auto leaf = art_policy::make_db_leaf_ptr(k, v, *this);
921+
auto leaf = art_policy::make_db_leaf_ptr(insert_key, v, *this);
925922
root = detail::node_ptr{leaf.release(), node_type::LEAF};
926923
return true;
927924
}
928925

929926
auto* node = &root;
930927
tree_depth_type depth{};
931-
auto remaining_key{k};
928+
auto remaining_key{insert_key};
932929

933930
while (true) {
934931
const auto node_type = node->type();
935932
if (node_type == node_type::LEAF) {
936933
auto* const leaf{node->template ptr<leaf_type*>()};
937934
const auto existing_key{leaf->get_key_view()};
938-
const auto cmp = k.cmp(existing_key);
935+
const auto cmp = insert_key.cmp(existing_key);
939936
if (UNODB_DETAIL_UNLIKELY(cmp == 0)) {
940937
return false; // exists
941938
}
942939
// Replace the existing leaf with a new N4 and put the existing
943940
// leaf and the leaf for the caller's key and value under the
944941
// new inode as its direct children.
945-
auto new_leaf = art_policy::make_db_leaf_ptr(k, v, *this);
942+
auto new_leaf = art_policy::make_db_leaf_ptr(insert_key, v, *this);
946943
auto new_node{inode_4::create(*this, existing_key, remaining_key, depth,
947944
leaf, std::move(new_leaf))};
948945
*node = detail::node_ptr{new_node.release(), node_type::I4};
@@ -963,7 +960,7 @@ bool db<Key, Value>::insert_internal(art_key_type k, value_type v) {
963960
// than the desired match. We need to split this inode into a
964961
// new N4 whose children are the existing inode and a new child
965962
// leaf.
966-
auto leaf = art_policy::make_db_leaf_ptr(k, v, *this);
963+
auto leaf = art_policy::make_db_leaf_ptr(insert_key, v, *this);
967964
auto new_node = inode_4::create(*this, *node, shared_prefix_len, depth,
968965
std::move(leaf));
969966
*node = detail::node_ptr{new_node.release(), node_type::I4};
@@ -982,7 +979,7 @@ bool db<Key, Value>::insert_internal(art_key_type k, value_type v) {
982979
remaining_key.shift_right(key_prefix_length);
983980

984981
node = inode->template add_or_choose_subtree<detail::node_ptr*>(
985-
node_type, remaining_key[0], k, v, *this, depth, node);
982+
node_type, remaining_key[0], insert_key, v, *this, depth, node);
986983

987984
if (node == nullptr) return true;
988985

@@ -993,12 +990,12 @@ bool db<Key, Value>::insert_internal(art_key_type k, value_type v) {
993990
UNODB_DETAIL_RESTORE_MSVC_WARNINGS()
994991

995992
template <typename Key, typename Value>
996-
bool db<Key, Value>::remove_internal(art_key_type k) {
993+
bool db<Key, Value>::remove_internal(art_key_type remove_key) {
997994
if (UNODB_DETAIL_UNLIKELY(root == nullptr)) return false;
998995

999996
if (root.type() == node_type::LEAF) {
1000997
auto* const root_leaf{root.ptr<leaf_type*>()};
1001-
if (root_leaf->matches(k)) {
998+
if (root_leaf->matches(remove_key)) {
1002999
const auto r{art_policy::reclaim_leaf_on_scope_exit(root_leaf, *this)};
10031000
root = nullptr;
10041001
return true;
@@ -1008,7 +1005,7 @@ bool db<Key, Value>::remove_internal(art_key_type k) {
10081005

10091006
auto* node = &root;
10101007
tree_depth_type depth{};
1011-
auto remaining_key{k};
1008+
auto remaining_key{remove_key};
10121009

10131010
while (true) {
10141011
const auto node_type = node->type();
@@ -1025,8 +1022,8 @@ bool db<Key, Value>::remove_internal(art_key_type k) {
10251022
remaining_key.shift_right(key_prefix_length);
10261023

10271024
const auto remove_result{inode->template remove_or_choose_subtree<
1028-
std::optional<detail::node_ptr*>>(node_type, remaining_key[0], k, *this,
1029-
node)};
1025+
std::optional<detail::node_ptr*>>(node_type, remaining_key[0],
1026+
remove_key, *this, node)};
10301027
if (UNODB_DETAIL_UNLIKELY(!remove_result)) return false;
10311028

10321029
auto* const child_ptr{*remove_result};

art_internal.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ class [[nodiscard]] tree_depth final {
249249
public:
250250
using value_type = std::uint32_t; // explicitly since also used in leaf.
251251

252+
// cppcheck-suppress passedByValue
252253
explicit constexpr tree_depth(value_type value_ = 0) noexcept
253254
: value{value_} {}
254255

@@ -262,6 +263,7 @@ class [[nodiscard]] tree_depth final {
262263
return *this;
263264
}
264265

266+
// cppcheck-suppress passedByValue
265267
constexpr void operator+=(value_type delta) noexcept { value += delta; }
266268

267269
private:

art_internal_impl.hpp

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class [[nodiscard]] basic_leaf final : public Header {
155155
//
156156
// TODO(thompsonbry) : Partial or no key in leaf?
157157
[[nodiscard, gnu::pure]] constexpr auto matches(
158+
// cppcheck-suppress passedByValue
158159
art_key_type k) const noexcept {
159160
return cmp(k) == 0;
160161
}
@@ -205,6 +206,7 @@ class [[nodiscard]] basic_leaf final : public Header {
205206
///
206207
/// \param val_size The size in bytes of the the value stored in the leaf.
207208
[[nodiscard, gnu::const]] static constexpr auto compute_size(
209+
// cppcheck-suppress passedByValue
208210
key_size_type key_size, value_size_type val_size) noexcept {
209211
return sizeof(basic_leaf<Key, Header>) + key_size + val_size -
210212
1 // because of the [1] byte on the end of the struct.
@@ -433,6 +435,7 @@ struct basic_art_policy final {
433435
return;
434436
}
435437
case node_type::I4: {
438+
// cppcheck-suppress throwInNoexceptFunction
436439
const auto r{make_db_inode_unique_ptr(
437440
node_ptr.template ptr<inode4_type *>(), db)};
438441
return;
@@ -1280,26 +1283,28 @@ class basic_inode_4 : public basic_inode_4_parent<ArtPolicy> {
12801283
using typename parent_class::node_ptr;
12811284
using tree_depth_type = tree_depth<art_key_type>;
12821285

1283-
constexpr basic_inode_4(db_type &, unodb::key_view k1,
1284-
art_key_type shifted_k2,
1286+
constexpr basic_inode_4(db_type&, unodb::key_view k1, art_key_type shifted_k2,
1287+
// cppcheck-suppress passedByValue
12851288
tree_depth_type depth) noexcept
12861289
: parent_class{k1, shifted_k2, depth} {}
12871290

1288-
constexpr basic_inode_4(db_type &, key_view k1, art_key_type shifted_k2,
1289-
tree_depth_type depth, leaf_type *child1,
1290-
db_leaf_unique_ptr &&child2) noexcept
1291+
constexpr basic_inode_4(db_type&, key_view k1, art_key_type shifted_k2,
1292+
// cppcheck-suppress passedByValue
1293+
tree_depth_type depth, leaf_type* child1,
1294+
db_leaf_unique_ptr&& child2) noexcept
12911295
: parent_class{k1, shifted_k2, depth} {
12921296
init(k1, shifted_k2, depth, child1, std::move(child2));
12931297
}
12941298

1295-
constexpr basic_inode_4(db_type &, node_ptr source_node,
1296-
unsigned len) noexcept
1297-
: parent_class{len, *source_node.template ptr<inode_type *>()} {}
1299+
// cppcheck-suppress passedByValue
1300+
constexpr basic_inode_4(db_type&, node_ptr source_node, unsigned len) noexcept
1301+
: parent_class{len, *source_node.template ptr<inode_type*>()} {}
12981302

1299-
constexpr basic_inode_4(db_type &, node_ptr source_node, unsigned len,
1303+
constexpr basic_inode_4(db_type&, node_ptr source_node, unsigned len,
1304+
// cppcheck-suppress passedByValue
13001305
tree_depth_type depth,
1301-
db_leaf_unique_ptr &&child1) noexcept
1302-
: parent_class{len, *source_node.template ptr<inode_type *>()} {
1306+
db_leaf_unique_ptr&& child1) noexcept
1307+
: parent_class{len, *source_node.template ptr<inode_type*>()} {
13031308
init(source_node, len, depth, std::move(child1));
13041309
}
13051310

@@ -1361,15 +1366,17 @@ class basic_inode_4 : public basic_inode_4_parent<ArtPolicy> {
13611366
}
13621367

13631368
constexpr void init(key_view k1, art_key_type shifted_k2,
1364-
tree_depth_type depth, const leaf_type *child1,
1365-
db_leaf_unique_ptr &&child2) noexcept {
1369+
// cppcheck-suppress passedByValue
1370+
tree_depth_type depth, const leaf_type* child1,
1371+
db_leaf_unique_ptr&& child2) noexcept {
13661372
const auto k2_next_byte_depth = this->get_key_prefix().length();
13671373
const auto k1_next_byte_depth = k2_next_byte_depth + depth;
13681374
add_two_to_empty(k1[k1_next_byte_depth], node_ptr{child1, node_type::LEAF},
13691375
shifted_k2[k2_next_byte_depth], std::move(child2));
13701376
}
13711377

1372-
constexpr void add_to_nonfull(db_leaf_unique_ptr &&child,
1378+
constexpr void add_to_nonfull(db_leaf_unique_ptr&& child,
1379+
// cppcheck-suppress passedByValue
13731380
tree_depth_type depth,
13741381
std::uint8_t children_count_) noexcept {
13751382
UNODB_DETAIL_ASSERT(children_count_ == this->children_count);

in_fake_critical_section.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ class [[nodiscard]] fake_read_critical_section final {
4040

4141
/// Check whether this fake read critical section is invalid after
4242
/// construction, always succeeds.
43+
// cppcheck-suppress functionStatic
4344
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
4445
[[nodiscard]] bool must_restart() const noexcept { return false; }
4546

4647
/// Check whether this fake read critical section is still valid, always
4748
/// succeeds.
49+
// cppcheck-suppress functionStatic
4850
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
4951
[[nodiscard]] bool check() UNODB_DETAIL_RELEASE_CONST noexcept {
5052
return true;
@@ -58,6 +60,7 @@ class [[nodiscard]] fake_read_critical_section final {
5860
}
5961

6062
/// Try to read unlock this read fake critical section, always succeeds.
63+
// cppcheck-suppress functionStatic
6164
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
6265
[[nodiscard]] bool try_read_unlock() const noexcept { return true; }
6366

@@ -72,6 +75,7 @@ class [[nodiscard]] fake_read_critical_section final {
7275
class [[nodiscard]] fake_lock final {
7376
public:
7477
/// Acquire and return an always-valid fake critical section for a fake lock.
78+
// cppcheck-suppress functionStatic
7579
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
7680
[[nodiscard]] fake_read_critical_section try_read_lock() noexcept {
7781
return fake_read_critical_section{};

0 commit comments

Comments
 (0)