Skip to content

Commit 180161b

Browse files
authored
Add -Wall to warning level in CI clang compilation (#8)
* Add -Wall and pedantic to warning level in CI clang compilation Signed-off-by: jparisu <javierparis@eprosima.com> * Fix -Wall warnings Signed-off-by: jparisu <javierparis@eprosima.com> * remove pedantic Signed-off-by: jparisu <javierparis@eprosima.com> Signed-off-by: jparisu <javierparis@eprosima.com>
1 parent 7a994bb commit 180161b

11 files changed

Lines changed: 38 additions & 35 deletions

File tree

.github/workflows/clang_colcon.meta

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[
88
"-DCMAKE_BUILD_TYPE=Release",
99
"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON",
10-
"-DCMAKE_CXX_FLAGS='-Werror'"
10+
"-DCMAKE_CXX_FLAGS='-Werror -Wall'",
1111
]
1212
}
1313
}

cpp_utils/include/cpp_utils/macros/custom_enumeration.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ namespace utils {
8484
{ os << to_string(e); return os; } \
8585
\
8686
/* Number of elements in enumeration */ \
87-
constexpr const unsigned int N_VALUES_ ## enumeration_name = COUNT_ARGUMENTS(__VA_ARGS__);
87+
constexpr const unsigned int N_VALUES_ ## enumeration_name = COUNT_ARGUMENTS(__VA_ARGS__)
8888

8989

9090
} /* namespace utils */

cpp_utils/include/cpp_utils/types/Fuzzy.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,19 +190,19 @@ class Fuzzy
190190
/////////////////////////
191191

192192
/**
193-
* @brief Fuzzy level of this object.
193+
* @brief Internal value of type \c T .
194194
*
195-
* This defines the certainty with which the internal \c value has been set.
196-
* By default is set to \c fuzzy_level_default if the internal value has not been set.
195+
* By default this value would be initialized with default constructor.
197196
*/
198-
FuzzyLevelType fuzzy_level = FuzzyLevelValues::fuzzy_level_default;
197+
T value = T();
199198

200199
/**
201-
* @brief Internal value of type \c T .
200+
* @brief Fuzzy level of this object.
202201
*
203-
* By default this value would be initialized with default constructor.
202+
* This defines the certainty with which the internal \c value has been set.
203+
* By default is set to \c fuzzy_level_default if the internal value has not been set.
204204
*/
205-
T value = T();
205+
FuzzyLevelType fuzzy_level = FuzzyLevelValues::fuzzy_level_default;
206206
};
207207

208208

cpp_utils/include/cpp_utils/wait/impl/WaitHandler.ipp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ template <typename T>
3636
WaitHandler<T>::WaitHandler(
3737
T init_value,
3838
bool enabled /* = true */)
39-
: enabled_(enabled)
39+
: value_(init_value)
40+
, enabled_(enabled)
4041
, threads_waiting_(0)
41-
, value_(init_value)
4242
{
4343
}
4444

cpp_utils/test/unittest/event/periodic_event/PeriodicEventHandlerTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ TEST(PeriodicEventHandlerTest, handler_period)
127127
// Wait twice for the period time
128128
handler.wait_for_event(2);
129129

130-
ASSERT_GE(calls.load(), 2) << calls;
130+
ASSERT_GE(calls.load(), 2u) << calls;
131131
}
132132
}
133133

@@ -143,7 +143,7 @@ TEST(PeriodicEventHandlerTest, handler_period_without_callback)
143143
std::this_thread::sleep_for(std::chrono::milliseconds(handler_period * 5)); // It should have activated 5 times
144144

145145
// Check it has not been activated
146-
ASSERT_EQ(handler.event_count(), 0);
146+
ASSERT_EQ(handler.event_count(), 0u);
147147
}
148148

149149
/**
@@ -165,7 +165,7 @@ TEST(PeriodicEventHandlerTest, limit_cases)
165165
// Wait 100 events for the period time
166166
handler.wait_for_event(100);
167167

168-
ASSERT_GE(handler.event_count(), 100);
168+
ASSERT_GE(handler.event_count(), 100u);
169169
}
170170

171171
// 1ms period and instant close

cpp_utils/test/unittest/event/signal/SignalEventHandlerTest.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ TEST(SignalEventHandlerTest, create_several_signal_handlers)
8484
// N signal handlers of SIGINT
8585
{
8686
std::vector<std::unique_ptr<SignalEventHandler<Signal::sigint>>> v;
87-
for (int i = 0; i < test::N_DEFAUL_TEST_EXECUTIONS; i++)
87+
for (unsigned int i = 0; i < test::N_DEFAUL_TEST_EXECUTIONS; i++)
8888
{
8989
v.push_back(std::make_unique<SignalEventHandler<Signal::sigint>>());
9090
}
@@ -93,7 +93,7 @@ TEST(SignalEventHandlerTest, create_several_signal_handlers)
9393
// N signal handlers of SIGTERM
9494
{
9595
std::vector<std::unique_ptr<SignalEventHandler<Signal::sigterm>>> v;
96-
for (int i = 0; i < test::N_DEFAUL_TEST_EXECUTIONS; i++)
96+
for (unsigned int i = 0; i < test::N_DEFAUL_TEST_EXECUTIONS; i++)
9797
{
9898
v.push_back(std::make_unique<SignalEventHandler<Signal::sigterm>>());
9999
}
@@ -102,7 +102,7 @@ TEST(SignalEventHandlerTest, create_several_signal_handlers)
102102
// N signal handlers of SIGINT & SIGTERM
103103
{
104104
std::vector<std::unique_ptr<IBaseSignalEventHandler>> v;
105-
for (int i = 0; i < test::N_DEFAUL_TEST_EXECUTIONS; i++)
105+
for (unsigned int i = 0; i < test::N_DEFAUL_TEST_EXECUTIONS; i++)
106106
{
107107
v.push_back(std::make_unique<SignalEventHandler<Signal::sigint>>());
108108
v.push_back(std::make_unique<SignalEventHandler<Signal::sigterm>>());
@@ -131,7 +131,7 @@ TEST(SignalEventHandlerTest, receive_signal_trivial)
131131
handler.wait_for_event();
132132

133133
// Check that signal has been received
134-
ASSERT_EQ(1, calls);
134+
ASSERT_EQ(calls, 1u);
135135
}
136136

137137
/**
@@ -168,7 +168,7 @@ TEST(SignalEventHandlerTest, receive_signal)
168168
handler2.wait_for_event();
169169

170170
// Check that signal has been received
171-
ASSERT_EQ(2, calls);
171+
ASSERT_EQ(calls, 2u);
172172
}
173173

174174
// SIGINT double signal
@@ -190,7 +190,7 @@ TEST(SignalEventHandlerTest, receive_signal)
190190
handler.wait_for_event(2);
191191

192192
// Check that signal has been received
193-
ASSERT_EQ(2, calls);
193+
ASSERT_EQ(calls, 2u);
194194
}
195195

196196
// SIGINT receive signal after unset
@@ -211,7 +211,7 @@ TEST(SignalEventHandlerTest, receive_signal)
211211
handler.wait_for_event();
212212

213213
// Check that signal has been received
214-
ASSERT_EQ(1, calls);
214+
ASSERT_EQ(calls, 1u);
215215

216216
// Unset callback, so new signal raise is not listened
217217

@@ -221,7 +221,7 @@ TEST(SignalEventHandlerTest, receive_signal)
221221
raise(static_cast<int>(Signal::sigint));
222222

223223
// Check that signal has not been received
224-
ASSERT_EQ(1, calls);
224+
ASSERT_EQ(calls, 1u);
225225
}
226226

227227
// SIGINT receive signal just before destroying
@@ -307,7 +307,7 @@ TEST(SignalEventHandlerTest, erase_callback_while_other_handling)
307307
handler2.wait_for_event();
308308

309309
// Check that signal has been received by both
310-
ASSERT_EQ(11, calls);
310+
ASSERT_EQ(calls, 11u);
311311

312312
// Unset handler 1 (adds 10)
313313
handler1.unset_callback();
@@ -319,7 +319,7 @@ TEST(SignalEventHandlerTest, erase_callback_while_other_handling)
319319
handler2.wait_for_event(2);
320320

321321
// Check that signal has been received by only 2 (that adds 1)
322-
ASSERT_EQ(12, calls);
322+
ASSERT_EQ(calls, 12u);
323323
}
324324

325325
int main(

cpp_utils/test/unittest/macros/enumerationBuilderMacrosTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ TEST(enumerationBuilderMacrosTest, n_values)
102102
TEST(enumerationBuilderMacrosTest, from_string)
103103
{
104104
// x each element inside
105-
for (int i = 0; i < test::N_VALUES_TestCustomEnum; i++)
105+
for (unsigned int i = 0; i < test::N_VALUES_TestCustomEnum; i++)
106106
{
107107
test::TestCustomEnum value = test::from_string_TestCustomEnum(test::string_values[i]);
108108
ASSERT_TRUE(value == test::enum_values[i]);
@@ -121,7 +121,7 @@ TEST(enumerationBuilderMacrosTest, from_string)
121121
TEST(enumerationBuilderMacrosTest, to_string)
122122
{
123123
// x each element inside
124-
for (int i = 0; i < test::N_VALUES_TestCustomEnum; i++)
124+
for (unsigned int i = 0; i < test::N_VALUES_TestCustomEnum; i++)
125125
{
126126
ASSERT_EQ(test::to_string(test::enum_values[i]), test::string_values[i]);
127127
}
@@ -136,7 +136,7 @@ TEST(enumerationBuilderMacrosTest, to_string)
136136
TEST(enumerationBuilderMacrosTest, serializator)
137137
{
138138
// x each element inside
139-
for (int i = 0; i < test::N_VALUES_TestCustomEnum; i++)
139+
for (unsigned int i = 0; i < test::N_VALUES_TestCustomEnum; i++)
140140
{
141141
std::stringstream ss;
142142
ss << test::enum_values[i];

cpp_utils/test/unittest/macros/macrosTest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ TEST(macrosTest, stringify)
4747
std::string(STRINGIFY(_random_value)),
4848
std::string("_random_value")
4949
);
50+
static_cast<void>(_random_value); // This is require to avoid unused-variable warning
5051

5152
// String
5253
std::string _random_string = "other value";
5354
ASSERT_EQ(
5455
std::string(STRINGIFY(_random_string)),
5556
std::string("_random_string")
5657
);
58+
static_cast<void>(_random_string); // This is require to avoid unused-variable warning
5759
}
5860
}
5961

cpp_utils/test/unittest/thread_pool/slot_thread_pool_test.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ namespace test {
2828
eprosima::utils::Duration_ms DEFAULT_TIME_TEST = 200u;
2929
eprosima::utils::Duration_ms RESIDUAL_TIME_TEST = DEFAULT_TIME_TEST / 2u;
3030

31-
uint32_t N_THREADS_IN_TEST = 10;
32-
uint32_t N_EXECUTIONS_IN_TEST = 5;
31+
// NOTE: These values are int and not unsigned int to simplify test code, as it avoids a cast
32+
constexpr const int N_THREADS_IN_TEST = 10;
33+
constexpr const int N_EXECUTIONS_IN_TEST = 5;
3334

3435
void test_lambda_increase_waiter(
3536
eprosima::utils::event::IntWaitHandler& counter,
@@ -73,7 +74,7 @@ TEST(slot_thread_pool_test, pool_one_thread_one_slot)
7374
);
7475

7576
// Emit task n times
76-
for (uint32_t i = 0; i < test::N_EXECUTIONS_IN_TEST; ++i)
77+
for (int i = 0; i < test::N_EXECUTIONS_IN_TEST; ++i)
7778
{
7879
thread_pool.emit(task_id);
7980
}
@@ -99,7 +100,7 @@ TEST(slot_thread_pool_test, pool_one_thread_n_slots)
99100
eprosima::utils::Timer timer;
100101

101102
// Create slot
102-
for (uint32_t i = 1; i <= test::N_EXECUTIONS_IN_TEST; ++i)
103+
for (int i = 1; i <= test::N_EXECUTIONS_IN_TEST; ++i)
103104
{
104105
TaskId task_id(i);
105106
thread_pool.slot(
@@ -113,7 +114,7 @@ TEST(slot_thread_pool_test, pool_one_thread_n_slots)
113114
}
114115

115116
// Emit every task 1 time
116-
for (uint32_t i = 1; i <= test::N_EXECUTIONS_IN_TEST; ++i)
117+
for (int i = 1; i <= test::N_EXECUTIONS_IN_TEST; ++i)
117118
{
118119
thread_pool.emit(TaskId(i));
119120
}
@@ -150,7 +151,7 @@ TEST(slot_thread_pool_test, pool_n_threads_one_slot)
150151
);
151152

152153
// Emit task n times
153-
for (uint32_t i = 0; i < test::N_EXECUTIONS_IN_TEST* test::N_THREADS_IN_TEST; ++i)
154+
for (int i = 0; i < test::N_EXECUTIONS_IN_TEST* test::N_THREADS_IN_TEST; ++i)
154155
{
155156
thread_pool.emit(task_id);
156157
}

cpp_utils/test/unittest/time/PausableTimerTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ TEST(PausableTimerTest, play_and_pause)
170170
sleep_for(test::TIME_WAIT_TEST);
171171

172172
// Check time
173-
ASSERT_EQ(0, timer.elapsed_ms());
173+
ASSERT_EQ(timer.elapsed_ms(), 0u);
174174
}
175175

176176
int main(

0 commit comments

Comments
 (0)