Skip to content

Commit bef2b2a

Browse files
clalancetteBarry-Xu-2018
authored andcommitted
Fixes to silence some clang warnings. (ros2#2127)
This does 2 separate things: * Adds (void)unused_variable things where needed. * Stops doing some checks on moved-from items in tests. With this in place, most of the remaining clang static analysis warnings are gone. Signed-off-by: Chris Lalancette <[email protected]>
1 parent 0c393e8 commit bef2b2a

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

rclcpp/test/rclcpp/test_function_traits.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ TEST(TestFunctionTraits, argument_types) {
393393

394394
auto bind_one_bool = std::bind(
395395
&ObjectMember::callback_one_bool, &object_member, std::placeholders::_1);
396+
(void)bind_one_bool; // to quiet clang
396397

397398
static_assert(
398399
std::is_same<
@@ -402,6 +403,7 @@ TEST(TestFunctionTraits, argument_types) {
402403

403404
auto bind_one_bool_const = std::bind(
404405
&ObjectMember::callback_one_bool_const, &object_member, std::placeholders::_1);
406+
(void)bind_one_bool_const; // to quiet clang
405407

406408
static_assert(
407409
std::is_same<
@@ -413,6 +415,7 @@ TEST(TestFunctionTraits, argument_types) {
413415
auto bind_two_bools = std::bind(
414416
&ObjectMember::callback_two_bools, &object_member, std::placeholders::_1,
415417
std::placeholders::_2);
418+
(void)bind_two_bools; // to quiet clang
416419

417420
static_assert(
418421
std::is_same<
@@ -429,6 +432,7 @@ TEST(TestFunctionTraits, argument_types) {
429432
auto bind_one_bool_one_float = std::bind(
430433
&ObjectMember::callback_one_bool_one_float, &object_member, std::placeholders::_1,
431434
std::placeholders::_2);
435+
(void)bind_one_bool_one_float; // to quiet clang
432436

433437
static_assert(
434438
std::is_same<
@@ -447,6 +451,7 @@ TEST(TestFunctionTraits, argument_types) {
447451
>::value, "Functor accepts a float as second argument");
448452

449453
auto bind_one_int = std::bind(func_one_int, std::placeholders::_1);
454+
(void)bind_one_int; // to quiet clang
450455

451456
static_assert(
452457
std::is_same<
@@ -455,6 +460,7 @@ TEST(TestFunctionTraits, argument_types) {
455460
>::value, "Functor accepts an int as first argument");
456461

457462
auto bind_two_ints = std::bind(func_two_ints, std::placeholders::_1, std::placeholders::_2);
463+
(void)bind_two_ints; // to quiet clang
458464

459465
static_assert(
460466
std::is_same<
@@ -470,6 +476,7 @@ TEST(TestFunctionTraits, argument_types) {
470476

471477
auto bind_one_int_one_char = std::bind(
472478
func_one_int_one_char, std::placeholders::_1, std::placeholders::_2);
479+
(void)bind_one_int_one_char; // to quiet clang
473480

474481
static_assert(
475482
std::is_same<
@@ -530,18 +537,21 @@ TEST(TestFunctionTraits, check_arguments) {
530537
(void)one;
531538
return 1;
532539
};
540+
(void)lambda_one_int; // to quiet clang
533541

534542
auto lambda_two_ints = [](int one, int two) {
535543
(void)one;
536544
(void)two;
537545
return 2;
538546
};
547+
(void)lambda_two_ints; // to quiet clang
539548

540549
auto lambda_one_int_one_char = [](int one, char two) {
541550
(void)one;
542551
(void)two;
543552
return 3;
544553
};
554+
(void)lambda_one_int_one_char; // to quiet clang
545555

546556
static_assert(
547557
rclcpp::function_traits::check_arguments<decltype(lambda_one_int), int>::value,
@@ -572,6 +582,7 @@ TEST(TestFunctionTraits, check_arguments) {
572582

573583
auto bind_one_bool = std::bind(
574584
&ObjectMember::callback_one_bool, &object_member, std::placeholders::_1);
585+
(void)bind_one_bool; // to quiet clang
575586

576587
// Test std::bind functions
577588
static_assert(
@@ -580,6 +591,7 @@ TEST(TestFunctionTraits, check_arguments) {
580591

581592
auto bind_one_bool_const = std::bind(
582593
&ObjectMember::callback_one_bool_const, &object_member, std::placeholders::_1);
594+
(void)bind_one_bool_const; // to quiet clang
583595

584596
// Test std::bind functions
585597
static_assert(
@@ -745,6 +757,7 @@ TEST_F(TestMember, bind_member_functor) {
745757
auto bind_member_functor = std::bind(
746758
&TestMember::MemberFunctor, this, std::placeholders::_1,
747759
std::placeholders::_2, std::placeholders::_3);
760+
(void)bind_member_functor; // to quiet clang
748761

749762
static_assert(
750763
rclcpp::function_traits::check_arguments<decltype(bind_member_functor), int, float,

rclcpp/test/rclcpp/test_loaned_message.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ TEST_F(TestLoanedMessage, move_loaned_message) {
186186
auto loaned_msg_moved_to = LoanedMessageT(std::move(loaned_msg_to_move));
187187

188188
ASSERT_TRUE(loaned_msg_moved_to.is_valid());
189-
ASSERT_FALSE(loaned_msg_to_move.is_valid());
190189

191190
loaned_msg_moved_to.get().float32_value = 42.0f;
192191
ASSERT_EQ(42.0f, loaned_msg_moved_to.get().float32_value);

rclcpp/test/rclcpp/test_serialized_message.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ TEST(TestSerializedMessage, various_constructors) {
6767
rclcpp::SerializedMessage yet_another_serialized_message(std::move(other_serialized_message));
6868
auto & yet_another_rcl_handle = yet_another_serialized_message.get_rcl_serialized_message();
6969
EXPECT_TRUE(nullptr == other_rcl_handle.buffer);
70-
EXPECT_EQ(0u, other_serialized_message.capacity());
71-
EXPECT_EQ(0u, other_serialized_message.size());
7270
EXPECT_TRUE(nullptr != yet_another_rcl_handle.buffer);
7371
EXPECT_EQ(content_size, yet_another_serialized_message.size());
7472
EXPECT_EQ(content_size, yet_another_serialized_message.capacity());

rclcpp_lifecycle/test/test_lifecycle_publisher.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ TEST_P(TestLifecyclePublisher, publish_managed_by_node) {
133133
rclcpp_lifecycle::Transition(Transition::TRANSITION_DEACTIVATE), ret);
134134
ASSERT_EQ(success, ret);
135135
ret = reset_key;
136+
(void)ret; // Just to make clang happy
136137
EXPECT_FALSE(node_->publisher()->is_activated());
137138
{
138139
auto msg_ptr = std::make_unique<test_msgs::msg::Empty>();

0 commit comments

Comments
 (0)