diff --git a/src/Configuration.cc b/src/Configuration.cc index 247dbd5c..36502d11 100644 --- a/src/Configuration.cc +++ b/src/Configuration.cc @@ -681,7 +681,7 @@ vector Configuration::getIncludePaths() const { vector include_paths; - for (auto path : paths) + for (const auto& path : paths) for (const auto& mapit : path.get_paths()) for (const auto& vecit : mapit.second) include_paths.emplace_back(vecit); diff --git a/src/ModelTree.cc b/src/ModelTree.cc index 6d8ae9a9..885ee717 100644 --- a/src/ModelTree.cc +++ b/src/ModelTree.cc @@ -1927,6 +1927,12 @@ ModelTree::initializeMEXCompilationWorkers(int numworkers, const filesystem::pat cout << "Spawning " << numworkers << " threads for compiling MEX files." << endl; for (int i {0}; i < numworkers; i++) + /* Passing the stop_token by const reference is ok (and makes clang-tidy happier), + since the std::jthread constructor calls the lambda with the return argument of the + get_stop_token() method, which returns a stop_token by value; hence there is no lifetime + issue. See: + https://stackoverflow.com/questions/72990607/const-stdstop-token-or-just-stdstop-token-as-parameter-for-thread-funct + */ mex_compilation_workers.emplace_back([](const stop_token& stoken) { unique_lock lk {mex_compilation_mut}; filesystem::path output; diff --git a/src/SubModel.cc b/src/SubModel.cc index 87844043..38b729ba 100644 --- a/src/SubModel.cc +++ b/src/SubModel.cc @@ -315,13 +315,13 @@ TrendComponentModelTable::writeOutput(const string& basename, ostream& output) c vector target_eqtags_vec = target_eqtags.at(name); output << "M_.trend_component." << name << ".target_eqtags = {"; - for (auto it : target_eqtags_vec) + for (const auto& it : target_eqtags_vec) output << "'" << it << "';"; output << "};" << endl; vector eqtags_vec = eqtags.at(name); output << "M_.trend_component." << name << ".target_eqn = ["; - for (auto it : target_eqtags_vec) + for (const auto& it : target_eqtags_vec) output << distance(eqtags_vec.begin(), find(eqtags_vec.begin(), eqtags_vec.end(), it)) + 1 << " "; output << "];" << endl; @@ -595,7 +595,7 @@ void VarModelTable::setLhs(map> lhs_arg) { lhs = move(lhs_arg); - for (auto it : lhs) + for (const auto& it : lhs) { vector lhsvec; for (auto ids : it.second) diff --git a/src/macro/Expressions.cc b/src/macro/Expressions.cc index 00855263..cfc6704b 100644 --- a/src/macro/Expressions.cc +++ b/src/macro/Expressions.cc @@ -1282,7 +1282,7 @@ void Array::print(ostream& output, bool matlab_output) const noexcept { output << (matlab_output ? "{" : "["); - for (bool printed_something {false}; auto e : arr) + for (bool printed_something {false}; const auto& e : arr) { if (exchange(printed_something, true)) output << ", "; @@ -1295,7 +1295,7 @@ void Tuple::print(ostream& output, bool matlab_output) const noexcept { output << (matlab_output ? "{" : "("); - for (bool printed_something {false}; auto e : tup) + for (bool printed_something {false}; const auto& e : tup) { if (exchange(printed_something, true)) output << ", "; @@ -1308,7 +1308,7 @@ void Function::printArgs(ostream& output) const noexcept { output << "("; - for (bool printed_something {false}; auto e : args) + for (bool printed_something {false}; const auto& e : args) { if (exchange(printed_something, true)) output << ", ";