Skip to content

Commit 8469555

Browse files
author
Goetz Gaycken
committed
Satisfy clang-tidy instead of switching off the false warning.
Instead of switching off the clang-tidy warning about uninitialized variables which are initialized just a couple of lines below, the variables are now initialized to bogus values which satisfies clang-tidy but disables better static analyzers or other tools to actually find real initialization problems.
1 parent 6cf07e7 commit 8469555

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

Core/include/Acts/Clusterization/InPlaceClusterization.hpp

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -214,27 +214,43 @@ void labelSortedCells(cell_collection_t &cells,
214214
for (index_t idx_a = 0; idx_a < cells.size(); ++idx_a) {
215215
traits::setLabel(cells[idx_a], idx_a);
216216
for (index_t idx_b = idx_a; idx_b-- > 0;) {
217-
// NOLINTBEGIN(cppcoreguidelines-pro-type-member-init)
218-
// all elements of diff will be set to a value no need to initialize
219-
// with a dummy value.
220-
std::array<coordinate_t, NDim> diff;
217+
// Unnecessary default initialization diff for the sole purpose of
218+
// satisfying clang-tidy. Although the number of array elements is known
219+
// at compile time, and proper initialization could be realized with some
220+
// recursive array generator, the solution would be too complicated for
221+
// this simple case.
222+
//
223+
// The implications are:
224+
// - the compiler may not optimize these unnecessary initialization
225+
// away, and
226+
// - proper static analyzers and tools like valgrind or memory
227+
// sanitizer would not be able to spot actual initialization
228+
// errors, since what concerns these tools the variables are
229+
// initialized.
230+
std::array<coordinate_t, NDim> diff{};
221231
for (unsigned int axis_i = 0; axis_i < NDim; ++axis_i) {
222232
diff[axis_i] =
223233
absDifference(traits::getCellCoordinate(cells[idx_a], axis_i),
224234
traits::getCellCoordinate(cells[idx_b], axis_i));
225235
}
226-
// NOLINTEND(cppcoreguidelines-pro-type-member-init)
227236

228237
if (connection_helper.isConnected(diff)) {
229238
if (traits::getLabel(cells[idx_a]) < idx_a) {
230-
// if the label is not its index, the cell was merged to a cluster
231-
// thus the two clusters need to be merged rather than just merging
232-
// in this one cell
233-
// NOLINTBEGIN(cppcoreguidelines-init-variables)
234-
// min_label and max_label will be set before use, no reason to set
235-
// to unused dummy value before.
236-
label_t min_label;
237-
label_t max_label;
239+
// Unnecessary initialization of min_label and max_label for the sole
240+
// purpose of satisfying clang-tidy. The correct values are only known
241+
// a couple of lines below and an alternative implementation which
242+
// would provide a correct initialization would make the code more
243+
// complicated.
244+
//
245+
// The implications are:
246+
// - the compiler may not optimize these unnecessary initialization
247+
// away, and
248+
// - proper static analyzers and tools like valgrind or memory
249+
// sanitizer would not be able to spot actual initialization
250+
// errors, since what concerns these tools the variables are
251+
// initialized.
252+
label_t min_label{};
253+
label_t max_label{};
238254
if (traits::getLabel(cells[idx_a]) < traits::getLabel(cells[idx_b])) {
239255
min_label = traits::getLabel(cells[idx_a]);
240256
max_label = traits::getLabel(cells[idx_b]);
@@ -244,7 +260,6 @@ void labelSortedCells(cell_collection_t &cells,
244260
min_label = traits::getLabel(cells[idx_b]);
245261
traits::setLabel(cells[idx_a], min_label);
246262
}
247-
// NOLINTEND(cppcoreguidelines-init-variables)
248263
// nothing will be done if the min and the max label are identical
249264
if (min_label != max_label) {
250265
// can only encounter cells with label max_label down to index

0 commit comments

Comments
 (0)