Skip to content

Commit a8f493a

Browse files
committed
Fix warnings
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent d6e0d2d commit a8f493a

File tree

14 files changed

+192
-111
lines changed

14 files changed

+192
-111
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ if(SOURCEMETA_CORE_DOCS)
117117
endif()
118118

119119
if(PROJECT_IS_TOP_LEVEL)
120+
# TODO: Try once more to enable this per target,
121+
# so, we don't need to manually disable it here
122+
sourcemeta_clang_tidy_attempt_disable()
120123
sourcemeta_target_clang_format(SOURCES
121124
src/*.h src/*.cc
122125
benchmark/*.h benchmark/*.cc

cmake/common/clang-tidy.cmake

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ function(sourcemeta_clang_tidy_attempt_enable)
106106

107107
# TODO: Support other platforms too, like Linux
108108
if(APPLE)
109-
execute_process(COMMAND xcrun --show-sdk-path
109+
execute_process(COMMAND xcrun --show-sdk-path
110110
OUTPUT_VARIABLE MACOSX_SDK_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
111-
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" -print-resource-dir
111+
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" -print-resource-dir
112112
OUTPUT_VARIABLE MACOSX_RESOURCE_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
113113
set(CMAKE_CXX_CLANG_TIDY
114114
"${CLANG_TIDY_BIN};--config-file=${CLANG_TIDY_CONFIG};-header-filter=${PROJECT_SOURCE_DIR}/src/*"
@@ -119,3 +119,7 @@ function(sourcemeta_clang_tidy_attempt_enable)
119119
PARENT_SCOPE)
120120
endif()
121121
endfunction()
122+
123+
function(sourcemeta_clang_tidy_attempt_disable)
124+
unset(CMAKE_CXX_CLANG_TIDY PARENT_SCOPE)
125+
endfunction()

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ template <typename T> struct HashJSON {
1414
return value.fast_hash();
1515
}
1616

17+
[[nodiscard]]
1718
inline auto is_perfect(const hash_type) const noexcept -> bool {
1819
return false;
1920
}
@@ -45,6 +46,7 @@ template <typename T> struct PropertyHashJSON {
4546
}
4647
};
4748

49+
[[nodiscard]]
4850
inline auto perfect(const T &value, const std::size_t size) const noexcept
4951
-> hash_type {
5052
hash_type result;
@@ -134,6 +136,7 @@ template <typename T> struct PropertyHashJSON {
134136
}
135137
}
136138

139+
[[nodiscard]]
137140
inline auto is_perfect(const hash_type &hash) const noexcept -> bool {
138141
// If there is anything written past the first byte,
139142
// then it is a perfect hash

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: 32 additions & 18 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()) {
@@ -580,14 +592,16 @@ template <typename PropertyT, typename Hash> class GenericPointer {
580592
}
581593

582594
/// Compare JSON Pointer instances
583-
auto operator==(const GenericPointer<PropertyT, Hash> &other) const noexcept
595+
[[nodiscard]] auto
596+
operator==(const GenericPointer<PropertyT, Hash> &other) const noexcept
584597
-> bool {
585598
return this->data == other.data;
586599
}
587600

588601
/// Overload to support ordering of JSON Pointers. Typically for sorting
589602
/// reasons.
590-
auto operator<(const GenericPointer<PropertyT, Hash> &other) const noexcept
603+
[[nodiscard]] auto
604+
operator<(const GenericPointer<PropertyT, Hash> &other) const noexcept
591605
-> bool {
592606
return this->data < other.data;
593607
}

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)