Skip to content

Commit 370fddf

Browse files
committed
clang-tidy gespräche
1 parent 15fadc6 commit 370fddf

File tree

16 files changed

+70
-31
lines changed

16 files changed

+70
-31
lines changed

.clang-tidy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# FIXME: all performance-* reports
33
# FIXME: all cert-* reports
44
# FIXME: all bugprone-* reports
5-
Checks: -*,bugprone-*,-bugprone-unhandled-self-assignment,-bugprone-parent-virtual-call,-bugprone-narrowing-conversions,-bugprone-exception-escape,-bugprone-string-literal-with-embedded-nul,cppcoreguidelines-slicing,mpi-*,readability-non-const-parameter,performance-*,-performance-avoid-endl,modernize-*,-modernize-use-trailing-return-type,-modernize-use-bool-literals,-modernize-avoid-c-arrays,-modernize-use-auto,-modernize-return-braced-init-list,-bugprone-easily-swappable-parameters
5+
Checks: -*,bugprone-*,-bugprone-unhandled-self-assignment,-bugprone-parent-virtual-call,-bugprone-narrowing-conversions,-bugprone-exception-escape,-bugprone-string-literal-with-embedded-nul,cppcoreguidelines-slicing,mpi-*,readability-non-const-parameter,performance-*,-performance-avoid-endl,modernize-*,-modernize-use-trailing-return-type,-modernize-use-bool-literals,-modernize-avoid-c-arrays,-modernize-use-auto,-modernize-return-braced-init-list,-bugprone-easily-swappable-parameters,-bugprone-chained-comparison
66
HeaderFilterRegex: '((^(?!\/share\/openPMD\/).*)*include\/openPMD\/.+\.hpp|src\/^(?!binding).+\.cpp$)'

examples/8b_benchmark_read_parallel.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ class Timer
135135
~Timer()
136136
{
137137
MPI_Barrier(MPI_COMM_WORLD);
138-
std::string tt = "~" + m_Tag;
139138
// MemoryProfiler (m_Rank, tt.c_str());
140139
m_End = std::chrono::system_clock::now();
141140

include/openPMD/IO/JSON/JSONIOHandlerImpl.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,7 @@ class JSONIOHandlerImpl : public AbstractIOHandlerImpl
525525
};
526526

527527
template <typename T>
528-
struct JsonToCpp<
529-
T,
530-
typename std::enable_if<std::is_floating_point<T>::value>::type>
528+
struct JsonToCpp<T, typename std::enable_if_t<std::is_floating_point_v<T>>>
531529
{
532530
T operator()(nlohmann::json const &);
533531
};

include/openPMD/backend/BaseRecord.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ class BaseRecord
317317
template <class InputIt>
318318
void insert(InputIt first, InputIt last);
319319
void insert(std::initializer_list<value_type> ilist);
320-
void swap(BaseRecord &other);
320+
void swap(BaseRecord &other) noexcept;
321321
bool contains(key_type const &key) const;
322322
template <class... Args>
323323
auto emplace(Args &&...args) -> std::pair<iterator, bool>;

src/IO/AbstractIOHandlerHelper.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ std::unique_ptr<AbstractIOHandler> createIOHandler<json::TracingJSON>(
8181
return constructIOHandler<ParallelHDF5IOHandler, openPMD_HAVE_HDF5>(
8282
"HDF5",
8383
std::move(initialize_from),
84-
path,
84+
std::move(path),
8585
access,
8686
comm,
8787
std::move(options));
@@ -139,7 +139,7 @@ std::unique_ptr<AbstractIOHandler> createIOHandler<json::TracingJSON>(
139139
return constructIOHandler<JSONIOHandler, openPMD_HAVE_JSON>(
140140
"JSON",
141141
std::move(initialize_from),
142-
path,
142+
std::move(path),
143143
access,
144144
comm,
145145
std::move(options),
@@ -149,7 +149,7 @@ std::unique_ptr<AbstractIOHandler> createIOHandler<json::TracingJSON>(
149149
return constructIOHandler<JSONIOHandler, openPMD_HAVE_JSON>(
150150
"JSON",
151151
std::move(initialize_from),
152-
path,
152+
std::move(path),
153153
access,
154154
comm,
155155
std::move(options),
@@ -181,7 +181,7 @@ std::unique_ptr<AbstractIOHandler> createIOHandler<json::TracingJSON>(
181181
return constructIOHandler<HDF5IOHandler, openPMD_HAVE_HDF5>(
182182
"HDF5",
183183
std::move(initialize_from),
184-
path,
184+
std::move(path),
185185
access,
186186
std::move(options));
187187
case Format::ADIOS2_BP:

src/IO/JSON/JSONIOHandlerImpl.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,13 +1203,13 @@ void JSONIOHandlerImpl::writeAttribute(
12031203
switch (m_attributeMode.m_mode)
12041204
{
12051205
case AttributeMode::Long:
1206-
(*jsonVal)[filePosition->id]["attributes"][parameter.name] = {
1206+
(*jsonVal)[filePosition->id]["attributes"][name] = {
12071207
{"datatype", jsonDatatypeToString(parameter.dtype)},
12081208
{"value", value}};
12091209
break;
12101210
case AttributeMode::Short:
12111211
// short form
1212-
(*jsonVal)[filePosition->id]["attributes"][parameter.name] = value;
1212+
(*jsonVal)[filePosition->id]["attributes"][name] = value;
12131213
break;
12141214
}
12151215
writable->written = true;
@@ -1540,7 +1540,6 @@ void JSONIOHandlerImpl::readAttribute(
15401540
auto const &jsonContents = obtainJsonContents(writable);
15411541
auto const &jsonLoc = jsonContents["attributes"];
15421542
setAndGetFilePosition(writable);
1543-
std::string error_msg("[JSON] No such attribute '");
15441543
if (!hasKey(jsonLoc, name))
15451544
{
15461545
throw error::ReadError(
@@ -2365,9 +2364,9 @@ nlohmann::json JSONIOHandlerImpl::platformSpecifics()
23652364
Datatype::CDOUBLE,
23662365
Datatype::CLONG_DOUBLE,
23672366
Datatype::BOOL};
2368-
for (auto it = std::begin(datatypes); it != std::end(datatypes); it++)
2367+
for (auto &datatype : datatypes)
23692368
{
2370-
res[jsonDatatypeToString(*it)] = toBytes(*it);
2369+
res[jsonDatatypeToString(datatype)] = toBytes(datatype);
23712370
}
23722371
return res;
23732372
}
@@ -2483,10 +2482,9 @@ std::array<T, n> JSONIOHandlerImpl::JsonToCpp<std::array<T, n>>::operator()(
24832482
}
24842483

24852484
template <typename T>
2486-
T JSONIOHandlerImpl::JsonToCpp<
2487-
T,
2488-
typename std::enable_if<std::is_floating_point<T>::value>::type>::
2489-
operator()(nlohmann::json const &j)
2485+
T JSONIOHandlerImpl::
2486+
JsonToCpp<T, std::enable_if_t<std::is_floating_point_v<T>>>::operator()(
2487+
nlohmann::json const &j)
24902488
{
24912489
try
24922490
{

src/RecordComponent.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ RecordComponent &RecordComponent::resetDataset(Dataset d)
132132
rc.m_isEmpty = false;
133133
if (written())
134134
{
135+
if (!rc.m_dataset.has_value())
136+
{
137+
throw error::Internal(
138+
"Internal control flow error: Written record component must "
139+
"have defined datatype and extent.");
140+
}
135141
rc.m_dataset.value().extend(std::move(d.extent));
136142
}
137143
else

src/Series.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,12 @@ void Series::initSeries(
10921092
series.m_filenamePrefix = input->filenamePrefix;
10931093
series.m_filenamePostfix = input->filenamePostfix;
10941094
series.m_filenamePadding = input->filenamePadding;
1095+
if (!input->filenameExtension)
1096+
{
1097+
throw error::Internal(
1098+
"Control flow error: filename extension has not been resolved.");
1099+
}
1100+
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
10951101
series.m_filenameExtension = input->filenameExtension.value();
10961102

10971103
if (series.m_iterationEncoding == IterationEncoding::fileBased &&
@@ -1704,7 +1710,8 @@ void Series::readFileBased(
17041710
{
17051711
if (forwardFirstError.has_value())
17061712
{
1707-
auto &firstError = forwardFirstError.value();
1713+
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
1714+
auto &firstError = *forwardFirstError;
17081715
firstError.description.append(
17091716
"\n[Note] Not a single iteration can be successfully "
17101717
"parsed (see above errors). Returning the first observed "
@@ -3406,7 +3413,7 @@ auto Series::currentSnapshot() -> std::optional<std::vector<IterationIndex_t>>
34063413
auto res = attribute.getOptional<vec_t>();
34073414
if (res.has_value())
34083415
{
3409-
return res.value();
3416+
return res;
34103417
}
34113418
else
34123419
{
@@ -3429,6 +3436,7 @@ AbstractIOHandler *Series::runDeferredInitialization()
34293436
auto &series = get();
34303437
if (series.m_deferred_initialization.has_value())
34313438
{
3439+
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
34323440
auto functor = std::move(*m_series->m_deferred_initialization);
34333441
m_series->m_deferred_initialization = std::nullopt;
34343442
return functor(*this);

src/auxiliary/Memory.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ allocatePtr(Datatype dtype, uint64_t numPoints)
4040
{
4141
using DT = Datatype;
4242
case DT::VEC_STRING:
43-
data = new char *[numPoints];
43+
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion)
44+
data = static_cast<void *>(new char *[numPoints]);
4445
del = [](void *p) { delete[] static_cast<char **>(p); };
4546
break;
4647
case DT::VEC_LONG_DOUBLE:

src/backend/Attribute.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ auto Attribute::get_impl() const -> std::variant<U, std::runtime_error>
7373
switch (index)
7474
{
7575
OPENPMD_FOREACH_DATATYPE(OPENPMD_ENUMERATE_TYPES)
76+
default:
77+
return {std::runtime_error("Unreachable!")};
7678
}
7779
#undef OPENPMD_ENUMERATE_TYPES
7880

0 commit comments

Comments
 (0)