Skip to content

Commit 05d411f

Browse files
committed
Increased warning levels
1 parent f7b6688 commit 05d411f

File tree

6 files changed

+22
-16
lines changed

6 files changed

+22
-16
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ project(sync_send)
44
set (CMAKE_CXX_STANDARD 23)
55
#set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-address-use-after-return=runtime")
66

7+
if (MSVC)
8+
add_compile_options(/W4 /WX)
9+
else()
10+
add_compile_options(-Wall -Wextra -pedantic -Werror)
11+
endif()
12+
713
enable_testing()
814
add_subdirectory(tests)
915
add_subdirectory(include/scl)

include/scl/utils/data_race_checker.test.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,12 @@ inline void test_no_data_race()
124124
// Then only read from the vector - no data race
125125
std::vector<std::thread> threads;
126126

127-
for (auto _ : std::ranges::iota_view (0, 3))
127+
for ([[maybe_unused]] auto _ : std::ranges::iota_view (0, 3))
128128
threads.emplace_back([&]
129129
{
130-
for (auto _ : std::ranges::iota_view (0uz, 1'000'000uz))
130+
for ([[maybe_unused]] auto _ : std::ranges::iota_view (0uz, 1'000'000uz))
131131
{
132-
volatile auto c = 0uz;
132+
[[maybe_unused]] volatile auto c = 0uz;
133133

134134
if (! vec.empty())
135135
c = vec[vec.size() - 1];
@@ -156,12 +156,12 @@ inline void test_data_race()
156156
}
157157
});
158158

159-
for (auto _ : std::ranges::iota_view (0, 3))
159+
for ([[maybe_unused]] auto _ : std::ranges::iota_view (0, 3))
160160
threads.emplace_back([&]
161161
{
162162
for (;;)
163163
{
164-
volatile auto c = 0uz;
164+
[[maybe_unused]] volatile auto c = 0uz;
165165

166166
if (! vec.empty())
167167
c = vec[vec.size() - 1];
@@ -183,12 +183,12 @@ inline void test_no_data_race_read_read()
183183
// Then only read from the vector - no data race
184184
std::vector<std::thread> threads;
185185

186-
for (auto _ : std::ranges::iota_view (0, 3))
186+
for ([[maybe_unused]] auto _ : std::ranges::iota_view (0, 3))
187187
threads.emplace_back([&]
188188
{
189-
for (auto _ : std::ranges::iota_view (0uz, 1'000'000uz))
189+
for ([[maybe_unused]] auto _ : std::ranges::iota_view (0uz, 1'000'000uz))
190190
{
191-
volatile auto c = 0uz;
191+
[[maybe_unused]] volatile auto c = 0uz;
192192

193193
if (! vec.empty())
194194
c = vec[vec.size() - 1];

tests/fail_empty_lambda_p.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ int main()
1414
// Launch all threads.
1515
const int num_threads = 15;
1616

17-
for (int i : std::views::iota (0, num_threads))
17+
for ([[maybe_unused]] int i : std::views::iota (0, num_threads))
1818
threads.push_back (scl::thread ([] { std::print ("Hello scl::thread"); }));
1919
}
2020

tests/fail_reference_capture_lambda.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ int main()
1515
const int num_threads = 15;
1616
int mol = 42;
1717

18-
for (int i : std::views::iota (0, num_threads))
18+
for ([[maybe_unused]] int i : std::views::iota (0, num_threads))
1919
{
20-
static_assert(! is_send_v<decltype([&mol] {})>);
20+
static_assert(! scl::is_send_v<decltype([&mol] { (void) mol; })>);
2121
threads.push_back (scl::thread ([&mol] { std::print ("Hello safe_thread {}", mol); }));
2222
}
2323
}

tests/fail_thread_runner.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ template <typename T>
99
struct is_send_test : std::integral_constant<
1010
bool,
1111
(! (std::is_lvalue_reference_v<T>
12-
|| is_lambda_v<T>))
12+
|| scl::is_lambda_v<T>))
1313
&&
1414
(std::is_pod_v<T>
1515
|| std::is_move_constructible_v<T>
16-
|| (is_function_pointer_v<std::decay_t<T>>
16+
|| (scl::is_function_pointer_v<std::decay_t<T>>
1717
&& ! std::is_member_function_pointer_v<T>)
18-
|| is_sync_v<T>)>
18+
|| scl::is_sync_v<T>)>
1919
{};
2020

2121
template<typename T> struct is_send_test<T*> : std::false_type {};
@@ -27,7 +27,7 @@ template<typename T> struct is_send_test<const T*&> : std::false_type {};
2727
template<typename T> struct is_send_test<const T*&&> : std::false_type {};
2828

2929
template<typename T>
30-
void check (T&& t) {
30+
void check (T&&) {
3131
static_assert (! is_send_test<T>::value);
3232
}
3333

tests/fail_thread_runner_with_pointer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class thread_runner
1010
public:
1111
thread_runner()
1212
{
13-
static_assert(! is_send_v<decltype([this] { return this; })>);
13+
static_assert(! scl::is_send_v<decltype([this] { return this; })>);
1414
int i = 42;
1515
auto i_ptr = &i;
1616
thread = std::make_unique<scl::thread> (std::mem_fn (&thread_runner::run), this, i_ptr);

0 commit comments

Comments
 (0)