Skip to content

Commit a3f71e7

Browse files
facontidavideclaude
andcommitted
Fix remaining clang-tidy warnings and update pre-commit exclusions
- Fix uninitialized std::array counters across test files - Add default member initializers in test node classes - Add anonymous namespaces for file-local functions - Add NOLINT comments for intentional patterns - Fix implicit bool conversions - Exclude optional-dependency files from clang-tidy (gmock, zmq, flatbuffers) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent e832469 commit a3f71e7

20 files changed

Lines changed: 108 additions & 54 deletions

‎.pre-commit-config.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ repos:
5151
entry: ./run_clang_tidy_hook.sh
5252
language: script
5353
files: \.(cpp|hpp|h)$
54-
exclude: ^3rdparty/|^include/behaviortree_cpp/contrib/|^include/behaviortree_cpp/scripting/
54+
exclude: ^3rdparty/|^include/behaviortree_cpp/contrib/|^include/behaviortree_cpp/scripting/|^include/behaviortree_cpp/flatbuffers/|^examples/|^tools/|^fuzzing/|^tests/gtest_async_action_node\.cpp$|^tests/gtest_logger_zmq\.cpp$|^tests/include/environment\.h$|^tests/gtest_groot2_publisher\.cpp$
5555

5656
# Spell check
5757
- repo: https://github.com/codespell-project/codespell

‎sample_nodes/crossdoor_nodes.cpp‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
#include "crossdoor_nodes.h"
22

3-
inline void SleepMS(int ms)
3+
namespace
4+
{
5+
6+
void SleepMS(int ms)
47
{
58
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
69
}
710

11+
} // namespace
12+
813
using BT::NodeStatus;
914

1015
NodeStatus CrossDoor::isDoorClosed()
@@ -77,6 +82,7 @@ void CrossDoor::reset()
7782

7883
// This function must be implemented in the .cpp file to create
7984
// a plugin that can be loaded at run-time
85+
// NOLINTNEXTLINE(misc-use-anonymous-namespace,misc-use-internal-linkage)
8086
BT_REGISTER_NODES(factory)
8187
{
8288
static CrossDoor cross_door;

‎tests/gtest_async_action_node.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct MockedThreadedAction : public BT::ThreadedAction
2121
// Tick while the node is running.
2222
BT::NodeStatus spinUntilDone()
2323
{
24+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-do-while)
2425
do
2526
{
2627
executeTick();

‎tests/gtest_blackboard.cpp‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,17 +191,23 @@ class RefCountClass
191191

192192
RefCountClass& operator=(const RefCountClass& from)
193193
{
194-
sptr_ = (from.sptr_);
195-
std::cout << "equal copied: ref_count " << sptr_.use_count() << std::endl;
194+
if(this != &from)
195+
{
196+
sptr_ = (from.sptr_);
197+
std::cout << "equal copied: ref_count " << sptr_.use_count() << std::endl;
198+
}
196199
return *this;
197200
}
198201

202+
RefCountClass(RefCountClass&&) = default;
203+
RefCountClass& operator=(RefCountClass&&) = default;
204+
199205
virtual ~RefCountClass()
200206
{
201207
std::cout << ("Destructor") << std::endl;
202208
}
203209

204-
int refCount() const
210+
long refCount() const
205211
{
206212
return sptr_.use_count();
207213
}
@@ -594,7 +600,7 @@ TEST(BlackboardTest, TimestampedInterface)
594600
auto bb = BT::Blackboard::create();
595601

596602
// still empty, expected to fail
597-
int value;
603+
int value = 0;
598604
ASSERT_FALSE(bb->getStamped<int>("value"));
599605
ASSERT_FALSE(bb->getStamped("value", value));
600606

‎tests/gtest_coroutines.cpp‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@ class SimpleCoroAction : public BT::CoroActionNode
7676
private:
7777
std::chrono::milliseconds timeout_;
7878
Timepoint start_time_;
79-
bool halted_;
79+
bool halted_ = false;
8080
};
8181

82+
namespace
83+
{
8284
BT::NodeStatus executeWhileRunning(BT::TreeNode& node)
8385
{
8486
auto status = node.executeTick();
@@ -89,6 +91,7 @@ BT::NodeStatus executeWhileRunning(BT::TreeNode& node)
8991
}
9092
return status;
9193
}
94+
} // namespace
9295

9396
TEST(CoroTest, do_action)
9497
{

‎tests/gtest_decorator.cpp‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ struct DeadlineTest : testing::Test
3737
root.setChild(&action);
3838
}
3939
~DeadlineTest() override = default;
40+
DeadlineTest(const DeadlineTest&) = delete;
41+
DeadlineTest& operator=(const DeadlineTest&) = delete;
42+
DeadlineTest(DeadlineTest&&) = delete;
43+
DeadlineTest& operator=(DeadlineTest&&) = delete;
4044
};
4145

4246
struct RepeatTest : testing::Test
@@ -49,6 +53,10 @@ struct RepeatTest : testing::Test
4953
root.setChild(&action);
5054
}
5155
~RepeatTest() override = default;
56+
RepeatTest(const RepeatTest&) = delete;
57+
RepeatTest& operator=(const RepeatTest&) = delete;
58+
RepeatTest(RepeatTest&&) = delete;
59+
RepeatTest& operator=(RepeatTest&&) = delete;
5260
};
5361

5462
struct RepeatTestAsync : testing::Test
@@ -61,6 +69,10 @@ struct RepeatTestAsync : testing::Test
6169
root.setChild(&action);
6270
}
6371
~RepeatTestAsync() override = default;
72+
RepeatTestAsync(const RepeatTestAsync&) = delete;
73+
RepeatTestAsync& operator=(const RepeatTestAsync&) = delete;
74+
RepeatTestAsync(RepeatTestAsync&&) = delete;
75+
RepeatTestAsync& operator=(RepeatTestAsync&&) = delete;
6476
};
6577

6678
struct RetryTest : testing::Test
@@ -73,6 +85,10 @@ struct RetryTest : testing::Test
7385
root.setChild(&action);
7486
}
7587
~RetryTest() override = default;
88+
RetryTest(const RetryTest&) = delete;
89+
RetryTest& operator=(const RetryTest&) = delete;
90+
RetryTest(RetryTest&&) = delete;
91+
RetryTest& operator=(RetryTest&&) = delete;
7692
};
7793

7894
struct TimeoutAndRetry : testing::Test
@@ -202,7 +218,7 @@ TEST_F(TimeoutAndRetry, Issue57)
202218
TEST(Decorator, RunOnce)
203219
{
204220
BT::BehaviorTreeFactory factory;
205-
std::array<int, 2> counters;
221+
std::array<int, 2> counters{};
206222
RegisterTestTick(factory, "Test", counters);
207223

208224
const std::string xml_text = R"(

‎tests/gtest_enums.cpp‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ enum class Color
1212
Undefined
1313
};
1414

15+
// NOLINTNEXTLINE(misc-use-anonymous-namespace,misc-use-internal-linkage)
1516
static const char* ToStr(const Color& c)
1617
{
1718
switch(c)
@@ -140,6 +141,10 @@ class PrintEnum : public BT::ConditionNode
140141
{}
141142

142143
~PrintEnum() override = default;
144+
PrintEnum(const PrintEnum&) = delete;
145+
PrintEnum& operator=(const PrintEnum&) = delete;
146+
PrintEnum(PrintEnum&&) = delete;
147+
PrintEnum& operator=(PrintEnum&&) = delete;
143148

144149
static BT::PortsList providedPorts()
145150
{
@@ -171,6 +176,10 @@ class IsHealthOk : public BT::ConditionNode
171176
{}
172177

173178
~IsHealthOk() override = default;
179+
IsHealthOk(const IsHealthOk&) = delete;
180+
IsHealthOk& operator=(const IsHealthOk&) = delete;
181+
IsHealthOk(IsHealthOk&&) = delete;
182+
IsHealthOk& operator=(IsHealthOk&&) = delete;
174183

175184
static BT::PortsList providedPorts()
176185
{

‎tests/gtest_port_type_rules.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ class NodeWithVectorPorts : public SyncActionNode
242242
NodeStatus tick() override
243243
{
244244
auto input = getInput<std::vector<double>>("input");
245-
if(input && result_)
245+
if(input && result_ != nullptr)
246246
{
247247
*result_ = input.value();
248248
return NodeStatus::SUCCESS;

‎tests/gtest_ports.cpp‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ template <>
312312
return std::to_string(point.x) + "," + std::to_string(point.y);
313313
}
314314

315+
// NOLINTNEXTLINE(misc-use-anonymous-namespace,misc-use-internal-linkage)
315316
BT_JSON_CONVERTER(Point2D, point)
316317
{
317318
add_field("x", &point.x);
@@ -444,7 +445,7 @@ TEST(PortTest, DefaultInputPoint2D)
444445
tree.subtrees.front()->blackboard->set<Point2D>("point", Point2D{ 3, 4 });
445446
tree.subtrees.front()->blackboard->set<Point2D>("pointD", Point2D{ 7, 8 });
446447

447-
BT::NodeStatus status;
448+
BT::NodeStatus status = NodeStatus::IDLE;
448449
ASSERT_NO_THROW(status = tree.tickOnce());
449450
ASSERT_EQ(status, NodeStatus::SUCCESS);
450451

@@ -507,7 +508,7 @@ TEST(PortTest, DefaultInputStrings)
507508
tree.subtrees.front()->blackboard->set<std::string>("msg", "ciao");
508509
tree.subtrees.front()->blackboard->set<std::string>("msgC", "hola");
509510

510-
BT::NodeStatus status;
511+
BT::NodeStatus status = NodeStatus::IDLE;
511512
ASSERT_NO_THROW(status = tree.tickOnce());
512513
ASSERT_EQ(status, NodeStatus::SUCCESS);
513514

@@ -781,6 +782,8 @@ TEST(PortTest, DefaultEmptyVector_Issue982)
781782
// Issue #989: JsonExporter::addConverter(std::function) had a use-after-move
782783
// bug where `converter` was moved into to_json_converters_ before
783784
// `vector_converter` captured it, causing bad_function_call at runtime.
785+
namespace
786+
{
784787
struct TestPoint989
785788
{
786789
double x = 0;
@@ -798,6 +801,7 @@ void TestPoint989FromJson(const nlohmann::json& j, TestPoint989& p)
798801
p.x = j.at("x").get<double>();
799802
p.y = j.at("y").get<double>();
800803
}
804+
} // namespace
801805

802806
TEST(PortTest, JsonExporterVectorConverter_Issue989)
803807
{

‎tests/gtest_preconditions.cpp‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ using namespace BT;
1212
TEST(PreconditionsDecorator, Integers)
1313
{
1414
BehaviorTreeFactory factory;
15-
std::array<int, 3> counters;
15+
std::array<int, 3> counters{};
1616
RegisterTestTick(factory, "Test", counters);
1717

1818
const std::string xml_text = R"(
@@ -45,7 +45,7 @@ TEST(PreconditionsDecorator, Integers)
4545
TEST(PreconditionsDecorator, DoubleEquals)
4646
{
4747
BehaviorTreeFactory factory;
48-
std::array<int, 3> counters;
48+
std::array<int, 3> counters{};
4949
RegisterTestTick(factory, "Test", counters);
5050

5151
const std::string xml_text = R"(
@@ -81,7 +81,7 @@ TEST(PreconditionsDecorator, DoubleEquals)
8181
TEST(PreconditionsDecorator, StringEquals)
8282
{
8383
BehaviorTreeFactory factory;
84-
std::array<int, 2> counters;
84+
std::array<int, 2> counters{};
8585
RegisterTestTick(factory, "Test", counters);
8686

8787
const std::string xml_text = R"(
@@ -172,7 +172,7 @@ TEST(PreconditionsDecorator, CanRunChildrenMultipleTimes)
172172
{
173173
BehaviorTreeFactory factory;
174174
factory.registerNodeType<KeepRunning>("KeepRunning");
175-
std::array<int, 1> counters;
175+
std::array<int, 1> counters{};
176176
RegisterTestTick(factory, "Test", counters);
177177

178178
const std::string xml_text = R"(
@@ -218,7 +218,7 @@ TEST(PreconditionsDecorator, CanRunChildrenMultipleTimes)
218218
TEST(Preconditions, Basic)
219219
{
220220
BehaviorTreeFactory factory;
221-
std::array<int, 4> counters;
221+
std::array<int, 4> counters{};
222222
RegisterTestTick(factory, "Test", counters);
223223

224224
const std::string xml_text = R"(
@@ -249,7 +249,7 @@ TEST(Preconditions, Basic)
249249
TEST(Preconditions, Issue533)
250250
{
251251
BehaviorTreeFactory factory;
252-
std::array<int, 3> counters;
252+
std::array<int, 3> counters{};
253253
RegisterTestTick(factory, "Test", counters);
254254

255255
const std::string xml_text = R"(
@@ -430,7 +430,7 @@ TEST(Preconditions, Remapping)
430430

431431
BehaviorTreeFactory factory;
432432

433-
std::array<int, 2> counters;
433+
std::array<int, 2> counters{};
434434
factory.registerNodeType<SimpleOutput>("SimpleOutput");
435435
RegisterTestTick(factory, "Test", counters);
436436

0 commit comments

Comments
 (0)