Skip to content

Commit 89ec116

Browse files
committed
fix modernize-use-nodiscard checks
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
1 parent 532a681 commit 89ec116

File tree

13 files changed

+184
-116
lines changed

13 files changed

+184
-116
lines changed

.clang-tidy

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
# See https://clang.llvm.org/extra/clang-tidy/index.html
33
# First disable all default checks (with -*)
44
Checks: '-*,
5-
bugprone-*,-bugprone-branch-clone,-bugprone-easily-swappable-parameters,-bugprone-empty-catch,
6-
clang-analyzer-*,
7-
clang-diagnostic-*,
8-
modernize-*,
9-
concurrency-*,
10-
cppcoreguidelines-*,-cppcoreguidelines-rvalue-reference-param-not-moved,
11-
performance-*,-performance-enum-size,
12-
portability-*,
13-
objc-*,
14-
misc-*,-misc-no-recursion,-misc-unused-parameters,-misc-const-correctness'
5+
modernize-use-nodiscard'
6+
# TODO(bavulapati): iterate through the rules and enable them incrementally inorder to send smaller PRs
7+
# bugprone-*,-bugprone-branch-clone,-bugprone-easily-swappable-parameters,-bugprone-empty-catch,
8+
# clang-analyzer-*,
9+
# clang-diagnostic-*,
10+
# modernize-*,
11+
# concurrency-*,
12+
# cppcoreguidelines-*,-cppcoreguidelines-rvalue-reference-param-not-moved,
13+
# performance-*,-performance-enum-size,
14+
# portability-*,
15+
# objc-*,
16+
# misc-*,-misc-no-recursion,-misc-unused-parameters,-misc-const-correctness'
1517
WarningsAsErrors: '*'
1618
FormatStyle: none
1719
UseColor: true

src/core/json/include/sourcemeta/core/json_array.h

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,31 +56,39 @@ template <typename Value> class JSONArray {
5656
/// Get a mutable end iterator on the array
5757
auto end() noexcept -> iterator { return this->data.end(); }
5858
/// Get a constant begin iterator on the array
59-
auto begin() const noexcept -> const_iterator { return this->data.begin(); }
59+
[[nodiscard]] auto begin() const noexcept -> const_iterator {
60+
return this->data.begin();
61+
}
6062
/// Get a constant end iterator on the array
61-
auto end() const noexcept -> const_iterator { return this->data.end(); }
63+
[[nodiscard]] auto end() const noexcept -> const_iterator {
64+
return this->data.end();
65+
}
6266
/// Get a constant begin iterator on the array
63-
auto cbegin() const noexcept -> const_iterator { return this->data.cbegin(); }
67+
[[nodiscard]] auto cbegin() const noexcept -> const_iterator {
68+
return this->data.cbegin();
69+
}
6470
/// Get a constant end iterator on the array
65-
auto cend() const noexcept -> const_iterator { return this->data.cend(); }
71+
[[nodiscard]] auto cend() const noexcept -> const_iterator {
72+
return this->data.cend();
73+
}
6674
/// Get a mutable reverse begin iterator on the array
6775
auto rbegin() noexcept -> reverse_iterator { return this->data.rbegin(); }
6876
/// Get a mutable reverse end iterator on the array
6977
auto rend() noexcept -> reverse_iterator { return this->data.rend(); }
7078
/// Get a constant reverse begin iterator on the array
71-
auto rbegin() const noexcept -> const_reverse_iterator {
79+
[[nodiscard]] auto rbegin() const noexcept -> const_reverse_iterator {
7280
return this->data.rbegin();
7381
}
7482
/// Get a constant reverse end iterator on the array
75-
auto rend() const noexcept -> const_reverse_iterator {
83+
[[nodiscard]] auto rend() const noexcept -> const_reverse_iterator {
7684
return this->data.rend();
7785
}
7886
/// Get a constant reverse begin iterator on the array
79-
auto crbegin() const noexcept -> const_reverse_iterator {
87+
[[nodiscard]] auto crbegin() const noexcept -> const_reverse_iterator {
8088
return this->data.crbegin();
8189
}
8290
/// Get a constant reverse end iterator on the array
83-
auto crend() const noexcept -> const_reverse_iterator {
91+
[[nodiscard]] auto crend() const noexcept -> const_reverse_iterator {
8492
return this->data.crend();
8593
}
8694

src/core/json/include/sourcemeta/core/json_hash.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ template <typename T> struct HashJSON {
1414
return value.fast_hash();
1515
}
1616

17-
inline auto is_perfect(const hash_type) const noexcept -> bool {
17+
[[nodiscard]] inline auto is_perfect(const hash_type) const noexcept -> bool {
1818
return false;
1919
}
2020
};
@@ -45,7 +45,8 @@ template <typename T> struct PropertyHashJSON {
4545
}
4646
};
4747

48-
inline auto perfect(const T &value, const std::size_t size) const noexcept
48+
[[nodiscard]] inline auto perfect(const T &value,
49+
const std::size_t size) const noexcept
4950
-> hash_type {
5051
hash_type result;
5152
assert(!value.empty());
@@ -134,7 +135,8 @@ template <typename T> struct PropertyHashJSON {
134135
}
135136
}
136137

137-
inline auto is_perfect(const hash_type &hash) const noexcept -> bool {
138+
[[nodiscard]] inline auto is_perfect(const hash_type &hash) const noexcept
139+
-> bool {
138140
// If there is anything written past the first byte,
139141
// then it is a perfect hash
140142
return hash.a > 255;

src/core/json/include/sourcemeta/core/json_object.h

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,21 @@ template <typename Key, typename Value, typename Hash> class FlatMap {
4646
}
4747
}
4848

49-
auto begin() const noexcept -> const_iterator { return this->data.begin(); }
50-
auto end() const noexcept -> const_iterator { return this->data.end(); }
51-
auto cbegin() const noexcept -> const_iterator { return this->data.cbegin(); }
52-
auto cend() const noexcept -> const_iterator { return this->data.cend(); }
49+
[[nodiscard]] auto begin() const noexcept -> const_iterator {
50+
return this->data.begin();
51+
}
52+
[[nodiscard]] auto end() const noexcept -> const_iterator {
53+
return this->data.end();
54+
}
55+
[[nodiscard]] auto cbegin() const noexcept -> const_iterator {
56+
return this->data.cbegin();
57+
}
58+
[[nodiscard]] auto cend() const noexcept -> const_iterator {
59+
return this->data.cend();
60+
}
5361

54-
inline auto hash(const key_type &key) const noexcept -> hash_type {
62+
[[nodiscard]] inline auto hash(const key_type &key) const noexcept
63+
-> hash_type {
5564
return this->hasher(key);
5665
}
5766

@@ -102,7 +111,8 @@ template <typename Key, typename Value, typename Hash> class FlatMap {
102111
}
103112

104113
// As a performance optimisation if the hash is known
105-
inline auto find(const key_type &key, const hash_type key_hash) const
114+
[[nodiscard]] inline auto find(const key_type &key,
115+
const hash_type key_hash) const
106116
-> const_iterator {
107117
assert(this->hash(key) == key_hash);
108118

@@ -129,7 +139,8 @@ template <typename Key, typename Value, typename Hash> class FlatMap {
129139
return this->cend();
130140
}
131141

132-
inline auto try_at(const key_type &key, const hash_type key_hash) const
142+
[[nodiscard]] inline auto try_at(const key_type &key,
143+
const hash_type key_hash) const
133144
-> const mapped_type * {
134145
assert(this->hash(key) == key_hash);
135146

@@ -153,7 +164,8 @@ template <typename Key, typename Value, typename Hash> class FlatMap {
153164
}
154165

155166
// As a performance optimisation if the hash is known
156-
auto contains(const key_type &key, const hash_type key_hash) const -> bool {
167+
[[nodiscard]] auto contains(const key_type &key,
168+
const hash_type key_hash) const -> bool {
157169
assert(this->hash(key) == key_hash);
158170

159171
// Move the perfect hash condition out of the loop for extra performance
@@ -176,7 +188,8 @@ template <typename Key, typename Value, typename Hash> class FlatMap {
176188

177189
// As a performance optimisation if the hash is known
178190

179-
inline auto at(const key_type &key, const hash_type key_hash) const
191+
[[nodiscard]] inline auto at(const key_type &key,
192+
const hash_type key_hash) const
180193
-> const mapped_type & {
181194
assert(this->hash(key) == key_hash);
182195

@@ -230,7 +243,8 @@ template <typename Key, typename Value, typename Hash> class FlatMap {
230243
#endif
231244
}
232245

233-
inline auto at(const size_type index) const noexcept -> const Entry & {
246+
[[nodiscard]] inline auto at(const size_type index) const noexcept
247+
-> const Entry & {
234248
return this->data[index];
235249
}
236250

@@ -285,9 +299,13 @@ template <typename Key, typename Value, typename Hash> class FlatMap {
285299
return this->erase(key, this->hash(key));
286300
}
287301

288-
inline auto size() const noexcept -> size_type { return this->data.size(); }
302+
[[nodiscard]] inline auto size() const noexcept -> size_type {
303+
return this->data.size();
304+
}
289305

290-
inline auto empty() const noexcept -> bool { return this->data.empty(); }
306+
[[nodiscard]] inline auto empty() const noexcept -> bool {
307+
return this->data.empty();
308+
}
291309

292310
inline auto clear() noexcept -> void { this->data.clear(); }
293311

@@ -386,44 +404,48 @@ template <typename Key, typename Value, typename Hash> class JSONObject {
386404
using const_pointer = typename Container::const_pointer;
387405
using const_iterator = typename Container::const_iterator;
388406

389-
inline auto begin() const noexcept -> const_iterator {
407+
[[nodiscard]] inline auto begin() const noexcept -> const_iterator {
390408
return this->data.begin();
391409
}
392410
/// Get a constant end iterator on the object
393-
inline auto end() const noexcept -> const_iterator {
411+
[[nodiscard]] inline auto end() const noexcept -> const_iterator {
394412
return this->data.end();
395413
}
396414
/// Get a constant begin iterator on the object
397-
inline auto cbegin() const noexcept -> const_iterator {
415+
[[nodiscard]] inline auto cbegin() const noexcept -> const_iterator {
398416
return this->data.cbegin();
399417
}
400418
/// Get a constant end iterator on the object
401-
inline auto cend() const noexcept -> const_iterator {
419+
[[nodiscard]] inline auto cend() const noexcept -> const_iterator {
402420
return this->data.cend();
403421
}
404422

405423
/// Attempt to find an entry by key
406-
inline auto find(const Key &key) const -> const_iterator {
424+
[[nodiscard]] inline auto find(const Key &key) const -> const_iterator {
407425
return this->data.find(key, this->data.hash(key));
408426
}
409427

410428
/// Check if an entry with the given key exists
411-
inline auto defines(const Key &key,
412-
const typename Container::hash_type hash) const -> bool {
429+
[[nodiscard]] inline auto
430+
defines(const Key &key, const typename Container::hash_type hash) const
431+
-> bool {
413432
return this->data.contains(key, hash);
414433
}
415434

416435
/// Check the size of the object
417-
inline auto size() const -> std::size_t { return this->data.size(); }
436+
[[nodiscard]] inline auto size() const -> std::size_t {
437+
return this->data.size();
438+
}
418439

419440
/// Access an object entry by its underlying positional index
420-
inline auto at(const size_type index) const noexcept -> const
441+
[[nodiscard]] inline auto at(const size_type index) const noexcept -> const
421442
typename Container::Entry & {
422443
return this->data.at(index);
423444
}
424445

425446
// Hash an object property
426-
inline auto hash(const Key &property) const -> typename Container::hash_type {
447+
[[nodiscard]] inline auto hash(const Key &property) const ->
448+
typename Container::hash_type {
427449
return this->data.hasher(property);
428450
}
429451

src/core/jsonpointer/include/sourcemeta/core/jsonpointer_pointer.h

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,31 +68,39 @@ template <typename PropertyT, typename Hash> class GenericPointer {
6868
/// Get a mutable end iterator on the pointer
6969
auto end() noexcept -> iterator { return this->data.end(); }
7070
/// Get a constant begin iterator on the pointer
71-
auto begin() const noexcept -> const_iterator { return this->data.begin(); }
71+
[[nodiscard]] auto begin() const noexcept -> const_iterator {
72+
return this->data.begin();
73+
}
7274
/// Get a constant end iterator on the pointer
73-
auto end() const noexcept -> const_iterator { return this->data.end(); }
75+
[[nodiscard]] auto end() const noexcept -> const_iterator {
76+
return this->data.end();
77+
}
7478
/// Get a constant begin iterator on the pointer
75-
auto cbegin() const noexcept -> const_iterator { return this->data.cbegin(); }
79+
[[nodiscard]] auto cbegin() const noexcept -> const_iterator {
80+
return this->data.cbegin();
81+
}
7682
/// Get a constant end iterator on the pointer
77-
auto cend() const noexcept -> const_iterator { return this->data.cend(); }
83+
[[nodiscard]] auto cend() const noexcept -> const_iterator {
84+
return this->data.cend();
85+
}
7886
/// Get a mutable reverse begin iterator on the pointer
7987
auto rbegin() noexcept -> reverse_iterator { return this->data.rbegin(); }
8088
/// Get a mutable reverse end iterator on the pointer
8189
auto rend() noexcept -> reverse_iterator { return this->data.rend(); }
8290
/// Get a constant reverse begin iterator on the pointer
83-
auto rbegin() const noexcept -> const_reverse_iterator {
91+
[[nodiscard]] auto rbegin() const noexcept -> const_reverse_iterator {
8492
return this->data.rbegin();
8593
}
8694
/// Get a constant reverse end iterator on the pointer
87-
auto rend() const noexcept -> const_reverse_iterator {
95+
[[nodiscard]] auto rend() const noexcept -> const_reverse_iterator {
8896
return this->data.rend();
8997
}
9098
/// Get a constant reverse begin iterator on the pointer
91-
auto crbegin() const noexcept -> const_reverse_iterator {
99+
[[nodiscard]] auto crbegin() const noexcept -> const_reverse_iterator {
92100
return this->data.crbegin();
93101
}
94102
/// Get a constant reverse end iterator on the pointer
95-
auto crend() const noexcept -> const_reverse_iterator {
103+
[[nodiscard]] auto crend() const noexcept -> const_reverse_iterator {
96104
return this->data.crend();
97105
}
98106

@@ -437,7 +445,7 @@ template <typename PropertyT, typename Hash> class GenericPointer {
437445
/// assert(left.concat(right) ==
438446
/// sourcemeta::core::Pointer{"foo", "bar", "baz"});
439447
/// ```
440-
auto concat(const GenericPointer<PropertyT, Hash> &other) const
448+
[[nodiscard]] auto concat(const GenericPointer<PropertyT, Hash> &other) const
441449
-> GenericPointer<PropertyT, Hash> {
442450
GenericPointer<PropertyT, Hash> result{*this};
443451
result.push_back(other);
@@ -455,7 +463,8 @@ template <typename PropertyT, typename Hash> class GenericPointer {
455463
/// const sourcemeta::core::Pointer prefix{"foo", "bar"};
456464
/// assert(pointer.starts_with(prefix));
457465
/// ```
458-
auto starts_with(const GenericPointer<PropertyT, Hash> &other) const -> bool {
466+
[[nodiscard]] auto
467+
starts_with(const GenericPointer<PropertyT, Hash> &other) const -> bool {
459468
return other.data.size() <= this->data.size() &&
460469
std::equal(other.data.cbegin(), other.data.cend(),
461470
this->data.cbegin());
@@ -473,8 +482,8 @@ template <typename PropertyT, typename Hash> class GenericPointer {
473482
/// const sourcemeta::core::Pointer prefix{"foo", "bar", "baz"};
474483
/// assert(pointer.starts_with(prefix, tail));
475484
/// ```
476-
auto starts_with(const GenericPointer<PropertyT, Hash> &other,
477-
const Token &tail) const -> bool {
485+
[[nodiscard]] auto starts_with(const GenericPointer<PropertyT, Hash> &other,
486+
const Token &tail) const -> bool {
478487
if (other.size() == this->size() + 1) {
479488
assert(!other.empty());
480489
return other.starts_with(*this) && other.back() == tail;
@@ -494,7 +503,8 @@ template <typename PropertyT, typename Hash> class GenericPointer {
494503
/// const sourcemeta::core::Pointer prefix{"foo", "bar", "qux"};
495504
/// assert(pointer.starts_with_initial(prefix));
496505
/// ```
497-
auto starts_with_initial(const GenericPointer<PropertyT, Hash> &other) const
506+
[[nodiscard]] auto
507+
starts_with_initial(const GenericPointer<PropertyT, Hash> &other) const
498508
-> bool {
499509
const auto prefix_size{other.size()};
500510
if (prefix_size == 0) {
@@ -525,8 +535,9 @@ template <typename PropertyT, typename Hash> class GenericPointer {
525535
/// assert(pointer.rebase(prefix, replacement) ==
526536
/// sourcemeta::core::Pointer{"qux", "baz"});
527537
/// ```
528-
auto rebase(const GenericPointer<PropertyT, Hash> &prefix,
529-
const GenericPointer<PropertyT, Hash> &replacement) const
538+
[[nodiscard]] auto
539+
rebase(const GenericPointer<PropertyT, Hash> &prefix,
540+
const GenericPointer<PropertyT, Hash> &replacement) const
530541
-> GenericPointer<PropertyT, Hash> {
531542
typename Container::size_type index{0};
532543
while (index < prefix.size()) {
@@ -560,7 +571,8 @@ template <typename PropertyT, typename Hash> class GenericPointer {
560571
///
561572
/// If the JSON Pointer is not relative to the base, a copy of the original
562573
/// input pointer is returned.
563-
auto resolve_from(const GenericPointer<PropertyT, Hash> &base) const
574+
[[nodiscard]] auto
575+
resolve_from(const GenericPointer<PropertyT, Hash> &base) const
564576
-> GenericPointer<PropertyT, Hash> {
565577
typename Container::size_type index{0};
566578
while (index < base.size()) {

src/core/jsonpointer/include/sourcemeta/core/jsonpointer_position.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ class SOURCEMETA_CORE_JSONPOINTER_EXPORT PointerPositionTracker {
5151
auto operator()(const JSON::ParsePhase phase, const JSON::Type,
5252
const std::uint64_t line, const std::uint64_t column,
5353
const JSON &value) -> void;
54-
auto get(const Pointer &pointer) const -> std::optional<Position>;
55-
auto size() const -> std::size_t;
54+
[[nodiscard]] auto get(const Pointer &pointer) const
55+
-> std::optional<Position>;
56+
[[nodiscard]] auto size() const -> std::size_t;
5657

5758
private:
5859
// Exporting symbols that depends on the standard C++ library is considered

0 commit comments

Comments
 (0)