Skip to content

Commit 6ecfa0d

Browse files
authored
Enable trailing return types for lambdas in clang-tidy (#828)
1 parent c1eb03b commit 6ecfa0d

9 files changed

Lines changed: 24 additions & 17 deletions

File tree

.clang-tidy

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ Checks: >
2828
-misc-const-correctness,
2929
-misc-non-private-member-variables-in-classes,
3030
-misc-use-internal-linkage,
31-
-modernize-use-trailing-return-type,
3231
-portability-avoid-pragma-once,
3332
-readability-inconsistent-ifelse-braces,
3433
-readability-magic-numbers
@@ -100,6 +99,10 @@ CheckOptions:
10099
value: 1
101100
- key: modernize-type-traits.IgnoreMacros
102101
value: 1
102+
- key: modernize-use-trailing-return-type.TransformFunctions
103+
value: false
104+
- key: modernize-use-trailing-return-type.TransformLambdas
105+
value: all_except_auto
103106
- key: cppcoreguidelines-avoid-goto.IgnoreMacros
104107
value: 1
105108
- key: readability-simplify-boolean-expr.ChainedConditionalReturn

modules/util/include/func_test_util.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class BaseRunFuncTests : public ::testing::TestWithParam<FuncTestParam<InType, O
6969
[this](const auto &test_param) { RunTestCase(test_param); });
7070
}
7171

72-
void ExecuteTest(FuncTestParam<InType, OutType, TestType> test_param) {
72+
void ExecuteTest(const FuncTestParam<InType, OutType, TestType> &test_param) {
7373
const auto &descriptor = GetTaskDescriptor(test_param);
7474

7575
ValidateTaskDescriptor(descriptor);

modules/util/include/perf_test_util.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,18 @@ void RunTaskForValidation(const ppc::task::TaskPtr<InType, OutType> &task) {
6565

6666
inline std::function<double()> MakeTechnologyTimer(ppc::task::TypeOfTask task_type) {
6767
if (task_type == ppc::task::TypeOfTask::kMPI || task_type == ppc::task::TypeOfTask::kALL) {
68-
return [] { return GetTimeMPI(); };
68+
return [] -> double { return GetTimeMPI(); };
6969
}
7070
if (task_type == ppc::task::TypeOfTask::kOMP) {
71-
return [] { return omp_get_wtime(); };
71+
return [] -> double { return omp_get_wtime(); };
7272
}
7373
if (task_type == ppc::task::TypeOfTask::kTBB) {
7474
const auto t0 = tbb::tick_count::now();
75-
return [t0] { return (tbb::tick_count::now() - t0).seconds(); };
75+
return [t0] -> double { return (tbb::tick_count::now() - t0).seconds(); };
7676
}
7777
if (task_type == ppc::task::TypeOfTask::kSEQ || task_type == ppc::task::TypeOfTask::kSTL) {
7878
const auto t0 = std::chrono::high_resolution_clock::now();
79-
return [t0] {
79+
return [t0] -> double {
8080
const auto now = std::chrono::high_resolution_clock::now();
8181
const auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(now - t0).count();
8282
return static_cast<double>(ns) * 1e-9;

modules/util/include/task_descriptor_util.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#pragma once
22

3+
#include <cstddef>
34
#include <string>
45
#include <string_view>
5-
#include <tuple>
66

77
#include "task/include/task.hpp"
88
#include "util/include/util.hpp"
@@ -17,8 +17,10 @@ inline ppc::task::TaskDescriptor MakeTaskDescriptor(std::string_view task_namesp
1717
const auto task_name = task_type == ppc::task::TypeOfTask::kUnknown
1818
? std::string(task_type_name)
1919
: std::string(task_type_name) + "_" + std::string(ppc::task::StatusOfTaskToString(status));
20-
return {task_type, status, ppc::task::TaskCategoryFromSettingsPath(settings_task_path),
21-
std::string(task_namespace) + "_" + task_name};
20+
return {.type = task_type,
21+
.status = status,
22+
.category = ppc::task::TaskCategoryFromSettingsPath(settings_task_path),
23+
.display_name = std::string(task_namespace) + "_" + task_name};
2224
}
2325

2426
template <typename TestParam>

modules/util/include/util.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ namespace test {
132132

133133
[[nodiscard]] inline std::string SanitizeToken(std::string_view token_sv) {
134134
std::string token{token_sv};
135-
auto is_allowed = [](char c) {
135+
auto is_allowed = [](char c) -> bool {
136136
return std::isalnum(static_cast<unsigned char>(c)) || c == '_' || c == '-' || c == '.';
137137
};
138138
std::ranges::replace(token, ' ', '_');

modules/util/tests/util.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,11 @@ using FuncTestUtilParam = ppc::util::FuncTestParam<int, int, int>;
138138

139139
FuncTestUtilParam MakeFuncTestUtilParam(const std::string &test_name, ppc::task::TypeOfTask task_type,
140140
ppc::task::StatusOfTask task_status, int value) {
141-
return FuncTestUtilParam{[](int) -> ppc::task::TaskPtr<int, int> {
142-
return {};
143-
}, test_name, value, ppc::task::TaskDescriptor{task_type, task_status, ppc::task::TaskCategory::kThreads, test_name}};
141+
return FuncTestUtilParam{[](int) -> ppc::task::TaskPtr<int, int> { return {}; }, test_name, value,
142+
ppc::task::TaskDescriptor{.type = task_type,
143+
.status = task_status,
144+
.category = ppc::task::TaskCategory::kThreads,
145+
.display_name = test_name}};
144146
}
145147

146148
void ExpectSingleNonFatalFailureContains(const ::testing::TestPartResultArray &failures, std::string_view message) {

tasks/example/threads/all/src/ops_all.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ bool NesterovATestTaskALL::RunImpl() {
6161
std::vector<std::thread> threads(num_threads);
6262
std::atomic<int> counter(0);
6363
for (std::thread &thread : threads) {
64-
thread = std::thread([&counter]() { counter++; });
64+
thread = std::thread([&counter]() -> void { counter++; });
6565
thread.join();
6666
}
6767
GetOutput() /= counter;
@@ -70,7 +70,7 @@ bool NesterovATestTaskALL::RunImpl() {
7070
{
7171
GetOutput() *= num_threads;
7272
std::atomic<int> counter(0);
73-
tbb::parallel_for(0, ppc::util::GetNumThreads(), [&](int /*i*/) { counter++; });
73+
tbb::parallel_for(0, ppc::util::GetNumThreads(), [&](int /*i*/) -> void { counter++; });
7474
GetOutput() /= counter;
7575
}
7676
MPI_Barrier(MPI_COMM_WORLD);

tasks/example/threads/stl/src/ops_stl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ bool NesterovATestTaskSTL::RunImpl() {
4242

4343
std::atomic<int> counter(0);
4444
for (std::thread &thread : threads) {
45-
thread = std::thread([&counter]() { counter++; });
45+
thread = std::thread([&counter]() -> void { counter++; });
4646
thread.join();
4747
}
4848

tasks/example/threads/tbb/src/ops_tbb.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ bool NesterovATestTaskTBB::RunImpl() {
4242
GetOutput() *= num_threads;
4343

4444
std::atomic<int> counter(0);
45-
tbb::parallel_for(0, ppc::util::GetNumThreads(), [&](int /*i*/) { counter++; });
45+
tbb::parallel_for(0, ppc::util::GetNumThreads(), [&](int /*i*/) -> void { counter++; });
4646

4747
GetOutput() /= counter;
4848
return GetOutput() > 0;

0 commit comments

Comments
 (0)