Skip to content

Commit 840e833

Browse files
authored
Merge pull request #928 from PowerGridModel/feature/clang-tidy-19
Clang tidy 19 support (bis)
2 parents 86e4188 + 88e07b1 commit 840e833

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+733
-444
lines changed

.clang-tidy

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Checks: '
66
-*,
77
boost-*,
8+
-boost-use-ranges,
89
bugprone-*,
910
-bugprone-easily-swappable-parameters,
1011
-bugprone-exception-escape,
@@ -55,6 +56,8 @@ readability-*,
5556
-readability-function-cognitive-complexity,
5657
-readability-identifier-length,
5758
-readability-magic-numbers,
59+
-readability-math-missing-parentheses,
60+
-readability-redundant-member-init,
5861
-bugprone-unchecked-optional-access,
5962
'
6063

@@ -64,4 +67,8 @@ WarningsAsErrors: '*'
6467
HeaderFilterRegex: '.*'
6568

6669
FormatStyle: file
70+
71+
CheckOptions:
72+
- key: performance-unnecessary-value-param.AllowedTypes
73+
- value: 'ForwardIterator'
6774
...

power_grid_model_c/power_grid_model/include/power_grid_model/auxiliary/dataset.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,9 @@ template <dataset_type_tag dataset_type_> class Dataset {
535535
throw DatasetError{"Cannot have duplicated components!\n"};
536536
}
537537
check_uniform_integrity(elements_per_scenario, total_elements);
538-
dataset_info_.component_info.push_back(
539-
{&dataset_info_.dataset->get_component(component), elements_per_scenario, total_elements});
538+
dataset_info_.component_info.push_back({.component = &dataset_info_.dataset->get_component(component),
539+
.elements_per_scenario = elements_per_scenario,
540+
.total_elements = total_elements});
540541
buffers_.push_back(Buffer{});
541542
}
542543

power_grid_model_c/power_grid_model/include/power_grid_model/auxiliary/serialization/deserializer.hpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ template <class T> struct DefaultErrorVisitor : DefaultNullVisitor {
186186
bool throw_error() { throw SerializationError{(static_cast<T&>(*this)).get_err_msg()}; }
187187

188188
std::string get_err_msg() { return std::string{T::static_err_msg}; }
189+
190+
private:
191+
DefaultErrorVisitor() = default;
192+
friend T; // CRTP compliance
189193
};
190194

191195
struct visit_map_t;
@@ -238,6 +242,8 @@ struct MapArrayVisitor : DefaultErrorVisitor<MapArrayVisitor<map_array>> {
238242
assert(size == 0);
239243
return true;
240244
}
245+
246+
MapArrayVisitor() = default;
241247
};
242248

243249
struct StringVisitor : DefaultErrorVisitor<StringVisitor> {
@@ -248,6 +254,8 @@ struct StringVisitor : DefaultErrorVisitor<StringVisitor> {
248254
str = {v, size};
249255
return true;
250256
}
257+
258+
StringVisitor() = default;
251259
};
252260

253261
struct BoolVisitor : DefaultErrorVisitor<BoolVisitor> {
@@ -258,6 +266,8 @@ struct BoolVisitor : DefaultErrorVisitor<BoolVisitor> {
258266
value = v;
259267
return true;
260268
}
269+
270+
BoolVisitor() = default;
261271
};
262272

263273
template <class T> struct ValueVisitor;
@@ -282,6 +292,8 @@ template <std::integral T> struct ValueVisitor<T> : DefaultErrorVisitor<ValueVis
282292
value = static_cast<T>(v);
283293
return true;
284294
}
295+
296+
ValueVisitor(T& v) : DefaultErrorVisitor<ValueVisitor<T>>{}, value{v} {}
285297
};
286298

287299
template <> struct ValueVisitor<double> : DefaultErrorVisitor<ValueVisitor<double>> {
@@ -306,6 +318,8 @@ template <> struct ValueVisitor<double> : DefaultErrorVisitor<ValueVisitor<doubl
306318
value = v;
307319
return true;
308320
}
321+
322+
ValueVisitor(double& v) : DefaultErrorVisitor<ValueVisitor<double>>{}, value{v} {}
309323
};
310324

311325
template <> struct ValueVisitor<RealValue<asymmetric_t>> : DefaultErrorVisitor<ValueVisitor<RealValue<asymmetric_t>>> {
@@ -357,6 +371,8 @@ template <> struct ValueVisitor<RealValue<asymmetric_t>> : DefaultErrorVisitor<V
357371
value[idx] = v;
358372
return true;
359373
}
374+
375+
ValueVisitor(RealValue<asymmetric_t>& v) : DefaultErrorVisitor<ValueVisitor<RealValue<asymmetric_t>>>{}, value{v} {}
360376
};
361377

362378
} // namespace detail
@@ -659,7 +675,8 @@ class Deserializer {
659675
size_t const scenario_offset = offset_;
660676
// skip all the real content but check if it has map
661677
bool const has_map = parse_skip_check_map();
662-
count_per_scenario.push_back({component_key_, component_size, scenario_offset, has_map});
678+
count_per_scenario.push_back(
679+
{.component = component_key_, .size = component_size, .offset = scenario_offset, .has_map = has_map});
663680
}
664681
component_key_ = {};
665682
return count_per_scenario;
@@ -708,8 +725,8 @@ class Deserializer {
708725
elements_per_scenario * batch_size; // multiply
709726
handler.add_component_info(component_key_, elements_per_scenario, total_elements);
710727
// check if all scenarios only contain array data
711-
bool const only_values_in_data = std::none_of(component_byte_meta.cbegin(), component_byte_meta.cend(),
712-
[](auto const& x) { return x.has_map; });
728+
bool const only_values_in_data =
729+
std::ranges::none_of(component_byte_meta, [](auto const& x) { return x.has_map; });
713730
msg_data_offsets_.push_back(std::move(component_byte_meta));
714731
// enable attribute indications if possible
715732
if (only_values_in_data) {
@@ -943,7 +960,7 @@ class Deserializer {
943960

944961
ctype_func_selector(attribute.ctype, [&buffer_view, &component, &attribute, this]<class T> {
945962
ValueVisitor<T> visitor{
946-
{}, attribute.get_attribute<T>(component.advance_ptr(buffer_view.buffer->data, buffer_view.idx))};
963+
attribute.get_attribute<T>(component.advance_ptr(buffer_view.buffer->data, buffer_view.idx))};
947964
msgpack::parse(data_, size_, offset_, visitor);
948965
});
949966
}
@@ -954,7 +971,7 @@ class Deserializer {
954971
assert(buffer.meta_attribute != nullptr);
955972

956973
ctype_func_selector(buffer.meta_attribute->ctype, [&buffer, &idx, this]<class T> {
957-
ValueVisitor<T> visitor{{}, *(reinterpret_cast<T*>(buffer.data) + idx)};
974+
ValueVisitor<T> visitor{*(reinterpret_cast<T*>(buffer.data) + idx)};
958975
msgpack::parse(data_, size_, offset_, visitor);
959976
});
960977
}

power_grid_model_c/power_grid_model/include/power_grid_model/auxiliary/serialization/serializer.hpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,19 @@ struct MapArray {
7373
bool begin{true};
7474
};
7575

76-
struct JsonConverter : msgpack::null_visitor {
76+
template <typename T> struct NullVisitor : msgpack::null_visitor {
77+
private:
78+
NullVisitor() = default;
79+
friend T; // CRTP compliance
80+
};
81+
82+
struct JsonConverter : NullVisitor<JsonConverter> {
7783
static constexpr char sep_char = ' ';
7884

7985
Idx indent{};
8086
Idx max_indent_level{};
81-
std::stringstream ss{}; // NOLINT(readability-redundant-member-init)
82-
std::stack<MapArray> map_array{}; // NOLINT(readability-redundant-member-init)
87+
std::stringstream ss{};
88+
std::stack<MapArray> map_array{};
8389

8490
void print_indent() {
8591
if (indent < 0) {
@@ -194,6 +200,9 @@ struct JsonConverter : msgpack::null_visitor {
194200
ss << '}';
195201
return true;
196202
}
203+
204+
JsonConverter(Idx indent_, Idx max_indent_level_)
205+
: NullVisitor<JsonConverter>{}, indent{indent_}, max_indent_level{max_indent_level_} {}
197206
};
198207

199208
} // namespace json_converter
@@ -380,7 +389,7 @@ class Serializer {
380389
std::string const& get_json(bool use_compact_list, Idx indent) {
381390
if (json_buffer_.empty() || (use_compact_list_ != use_compact_list) || (json_indent_ != indent)) {
382391
Idx const max_indent_level = dataset_handler_.is_batch() ? 4 : 3;
383-
json_converter::JsonConverter visitor{{}, indent, max_indent_level};
392+
json_converter::JsonConverter visitor{indent, max_indent_level};
384393
auto const msgpack_data = get_msgpack(use_compact_list);
385394
msgpack::parse(msgpack_data.data(), msgpack_data.size(), visitor);
386395
json_buffer_ = visitor.ss.str();

power_grid_model_c/power_grid_model/include/power_grid_model/common/common.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct Idx2D {
3131
};
3232

3333
struct Idx2DHash {
34-
std::size_t operator()(const Idx2D& idx) const {
34+
std::size_t operator()(Idx2D const& idx) const {
3535
size_t const h1 = std::hash<Idx>{}(idx.group);
3636
size_t const h2 = std::hash<Idx>{}(idx.pos);
3737
return h1 ^ (h2 << 1);

0 commit comments

Comments
 (0)