Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Checks: [
"-*",
"bugprone-*",
"cert-*",
"clang-analyzer-*",
"concurrency-*",
"cppcoreguidelines-*",
"misc-*",
"modernize-*",
"performance-*",
"portability-*",
"readability-*",
"-bugprone-easily-swappable-parameters",
"-bugprone-narrowing-conversions",
"-cert-err58-cpp",
"-cppcoreguidelines-avoid-c-arrays",
"-cppcoreguidelines-avoid-magic-numbers",
"-cppcoreguidelines-avoid-non-const-global-variables",
"-cppcoreguidelines-non-private-member-variables-in-classes",
"-cppcoreguidelines-pro-bounds-array-to-pointer-decay",
"-cppcoreguidelines-pro-bounds-constant-array-index",
"-cppcoreguidelines-pro-bounds-pointer-arithmetic",
"-cppcoreguidelines-pro-type-const-cast",
"-cppcoreguidelines-pro-type-union-access",
"-cppcoreguidelines-pro-type-vararg",
"-misc-no-recursion",
"-misc-non-private-member-variables-in-classes"
]


WarningsAsErrors: '-*,bugprone-*,cert-*,clang-analyzer-*,concurrency-*,cppcoreguidelines-*,misc-*,portability-*,readability-implicit-bool-conversion,-concurrency-mt-unsafe,-readability-function-cognitive-complexity'

CheckOptions:
# ignore macros when computing the cyclomatic complexity. problem caused by RCLCPP LOG macros
- key: readability-function-cognitive-complexity.IgnoreMacros
value: 'true'

# This change makes it compatible with MISRA:2023 rule 4.14.1
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: 'true'

# Making a copy of a shared_ptr has a non-zero cost, but this cost is small.
# Unfortunately the ROS API (subscriber callbacks) oblige the user to use callbacks functions that will trigger this warning
# This is the reason wht the warning is silenced here
- key: performance-unnecessary-value-param.AllowedTypes
value: 'std::shared_ptr'

# Reference: https://clang.llvm.org/extra/clang-tidy/checks/readability/identifier-naming.html
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
27 changes: 25 additions & 2 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,29 @@ jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: pre-commit/[email protected]

clang-tidy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install LLVM 21
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 21
sudo apt-get install -y clangd-21 clang-tidy-21

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libzmq3-dev libsqlite3-dev

- name: Configure CMake
run: cmake -B build -DBUILD_TESTING=OFF

- name: Run clang-tidy
run: ./run_clang_tidy.sh
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ site/*
/.vscode/
.vs/

# clangd cache
# clangd cache and config (generated by CMake)
/.cache/*
/.clangd
CMakeSettings.json

# OSX junk
Expand All @@ -18,3 +19,6 @@ CMakeSettings.json
CMakeUserPresets.json

tags
/clang_tidy_output.log
/.clang-tidy-venv/*
/llvm.sh
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ repos:
- id: clang-format
args: ['-fallback-style=none', '-i']

# C++ static analysis (installs clang-tidy automatically via pip)
# - repo: https://github.com/mxmlnrdr/clang_tidy_hook
# rev: v0.3.1
# hooks:
# - id: clang-tidy
# args:
# - --config-file=.clang-tidy
# - -p=build

# Spell check
- repo: https://github.com/codespell-project/codespell
rev: v2.4.1
Expand Down
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,21 @@ if(BTCPP_EXAMPLES)
add_subdirectory(examples)
endif()

######################################################
# Generate .clangd configuration file for standalone header checking
file(WRITE ${CMAKE_SOURCE_DIR}/.clangd
"CompileFlags:
Add:
- -xc++
- -std=c++17
- -I${CMAKE_SOURCE_DIR}/include
- -I${CMAKE_SOURCE_DIR}/3rdparty
- -I${CMAKE_SOURCE_DIR}/3rdparty/minitrace
- -I${CMAKE_SOURCE_DIR}/3rdparty/tinyxml2
- -I${CMAKE_SOURCE_DIR}/3rdparty/minicoro
- -I${CMAKE_SOURCE_DIR}/3rdparty/lexy/include
")

######################################################
# INSTALL

Expand Down
24 changes: 22 additions & 2 deletions include/behaviortree_cpp/action_node.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Copyright (C) 2015-2018 Michele Colledanchise - All Rights Reserved
* Copyright (C) 2018-2020 Davide Faconti, Eurecat - All Rights Reserved
* Copyright (C) 2018-2025 Davide Faconti, Eurecat - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
Expand Down Expand Up @@ -38,6 +38,11 @@ class ActionNodeBase : public LeafNode
ActionNodeBase(const std::string& name, const NodeConfig& config);
~ActionNodeBase() override = default;

ActionNodeBase(const ActionNodeBase&) = delete;
ActionNodeBase& operator=(const ActionNodeBase&) = delete;
ActionNodeBase(ActionNodeBase&&) = delete;
ActionNodeBase& operator=(ActionNodeBase&&) = delete;

virtual NodeType type() const override final
{
return NodeType::ACTION;
Expand All @@ -55,6 +60,11 @@ class SyncActionNode : public ActionNodeBase
SyncActionNode(const std::string& name, const NodeConfig& config);
~SyncActionNode() override = default;

SyncActionNode(const SyncActionNode&) = delete;
SyncActionNode& operator=(const SyncActionNode&) = delete;
SyncActionNode(SyncActionNode&&) = delete;
SyncActionNode& operator=(SyncActionNode&&) = delete;

/// throws if the derived class return RUNNING.
virtual NodeStatus executeTick() override;

Expand Down Expand Up @@ -87,6 +97,11 @@ class SimpleActionNode : public SyncActionNode

~SimpleActionNode() override = default;

SimpleActionNode(const SimpleActionNode&) = delete;
SimpleActionNode& operator=(const SimpleActionNode&) = delete;
SimpleActionNode(SimpleActionNode&&) = delete;
SimpleActionNode& operator=(SimpleActionNode&&) = delete;

protected:
virtual NodeStatus tick() override final;

Expand Down Expand Up @@ -197,7 +212,12 @@ class CoroActionNode : public ActionNodeBase
{
public:
CoroActionNode(const std::string& name, const NodeConfig& config);
virtual ~CoroActionNode() override;
~CoroActionNode() override;

CoroActionNode(const CoroActionNode&) = delete;
CoroActionNode& operator=(const CoroActionNode&) = delete;
CoroActionNode(CoroActionNode&&) = delete;
CoroActionNode& operator=(CoroActionNode&&) = delete;

/// Use this method to return RUNNING and temporary "pause" the Action.
void setStatusRunningAndYield();
Expand Down
2 changes: 1 addition & 1 deletion include/behaviortree_cpp/actions/always_failure_node.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2018-2020 Davide Faconti, Eurecat - All Rights Reserved
/* Copyright (C) 2018-2025 Davide Faconti, Eurecat - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
Expand Down
2 changes: 1 addition & 1 deletion include/behaviortree_cpp/actions/always_success_node.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2018-2022 Davide Faconti, Eurecat - All Rights Reserved
/* Copyright (C) 2018-2025 Davide Faconti, Eurecat - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
Expand Down
25 changes: 8 additions & 17 deletions include/behaviortree_cpp/actions/pop_from_queue.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2022 Davide Faconti - All Rights Reserved
/* Copyright (C) 2022-2025 Davide Faconti - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
Expand Down Expand Up @@ -71,18 +71,12 @@ class PopFromQueue : public SyncActionNode
{
return NodeStatus::FAILURE;
}
else
{
T val = items.front();
items.pop_front();
setOutput("popped_item", val);
return NodeStatus::SUCCESS;
}
}
else
{
return NodeStatus::FAILURE;
T val = items.front();
items.pop_front();
setOutput("popped_item", val);
return NodeStatus::SUCCESS;
}
return NodeStatus::FAILURE;
}

static PortsList providedPorts()
Expand Down Expand Up @@ -125,11 +119,8 @@ class QueueSize : public SyncActionNode
{
return NodeStatus::FAILURE;
}
else
{
setOutput("size", int(items.size()));
return NodeStatus::SUCCESS;
}
setOutput("size", int(items.size()));
return NodeStatus::SUCCESS;
}
return NodeStatus::FAILURE;
}
Expand Down
2 changes: 1 addition & 1 deletion include/behaviortree_cpp/actions/script_condition.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2023 Davide Faconti - All Rights Reserved
/* Copyright (C) 2023-2025 Davide Faconti - All Rights Reserved
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
Expand Down
2 changes: 1 addition & 1 deletion include/behaviortree_cpp/actions/script_node.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2022 Davide Faconti - All Rights Reserved
/* Copyright (C) 2022-2025 Davide Faconti - All Rights Reserved
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
Expand Down
2 changes: 1 addition & 1 deletion include/behaviortree_cpp/actions/set_blackboard_node.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2018-2020 Davide Faconti, Eurecat - All Rights Reserved
/* Copyright (C) 2018-2025 Davide Faconti, Eurecat - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
Expand Down
7 changes: 6 additions & 1 deletion include/behaviortree_cpp/actions/sleep_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class SleepNode : public StatefulActionNode
halt();
}

SleepNode(const SleepNode&) = delete;
SleepNode& operator=(const SleepNode&) = delete;
SleepNode(SleepNode&&) = delete;
SleepNode& operator=(SleepNode&&) = delete;

NodeStatus onStart() override;

NodeStatus onRunning() override;
Expand All @@ -35,7 +40,7 @@ class SleepNode : public StatefulActionNode

private:
TimerQueue<> timer_;
uint64_t timer_id_;
uint64_t timer_id_ = 0;

std::atomic_bool timer_waiting_ = false;
std::mutex delay_mutex_;
Expand Down
2 changes: 1 addition & 1 deletion include/behaviortree_cpp/actions/test_node.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2022 Davide Faconti - All Rights Reserved
/* Copyright (C) 2022-2025 Davide Faconti - All Rights Reserved
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
Expand Down
2 changes: 1 addition & 1 deletion include/behaviortree_cpp/actions/unset_blackboard_node.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2023 Davide Faconti - All Rights Reserved
/* Copyright (C) 2023-2025 Davide Faconti - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
Expand Down
7 changes: 6 additions & 1 deletion include/behaviortree_cpp/actions/updated_action.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2024 Davide Faconti - All Rights Reserved
/* Copyright (C) 2024-2025 Davide Faconti - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
Expand Down Expand Up @@ -30,6 +30,11 @@ class EntryUpdatedAction : public SyncActionNode

~EntryUpdatedAction() override = default;

EntryUpdatedAction(const EntryUpdatedAction&) = delete;
EntryUpdatedAction& operator=(const EntryUpdatedAction&) = delete;
EntryUpdatedAction(EntryUpdatedAction&&) = delete;
EntryUpdatedAction& operator=(EntryUpdatedAction&&) = delete;

static PortsList providedPorts()
{
return { InputPort<BT::Any>("entry", "Entry to check") };
Expand Down
5 changes: 4 additions & 1 deletion include/behaviortree_cpp/basic_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,11 @@ class PortInfo : public TypeInfo
{
default_value_str_ = BT::toStr(default_value);
}
// NOLINTNEXTLINE(bugprone-empty-catch)
catch(LogicError&)
{}
{
// conversion to string not available for this type, ignore
}
}

[[nodiscard]] const std::string& description() const;
Expand Down
2 changes: 1 addition & 1 deletion include/behaviortree_cpp/behavior_tree.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Copyright (C) 2015-2018 Michele Colledanchise - All Rights Reserved
* Copyright (C) 2018-2023 Davide Faconti - All Rights Reserved
* Copyright (C) 2018-2025 Davide Faconti - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
Expand Down
11 changes: 10 additions & 1 deletion include/behaviortree_cpp/blackboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ class Blackboard
{}

public:
Blackboard(const Blackboard&) = delete;
Blackboard& operator=(const Blackboard&) = delete;
Blackboard(Blackboard&&) = delete;
Blackboard& operator=(Blackboard&&) = delete;

struct Entry
{
Any value;
Expand All @@ -54,7 +59,11 @@ class Blackboard
Entry(const TypeInfo& _info) : info(_info)
{}

Entry& operator=(const Entry& other);
~Entry() = default;
Entry(const Entry&) = delete;
Entry& operator=(const Entry&) = delete;
Entry(Entry&&) = delete;
Entry& operator=(Entry&&) = delete;
};

/** Use this static method to create an instance of the BlackBoard
Expand Down
4 changes: 3 additions & 1 deletion include/behaviortree_cpp/bt_factory.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Copyright (C) 2018 Michele Colledanchise - All Rights Reserved
* Copyright (C) 2018-2023 Davide Faconti - All Rights Reserved
* Copyright (C) 2018-2025 Davide Faconti - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
Expand Down Expand Up @@ -78,8 +78,10 @@ inline TreeNodeManifest CreateManifest(const std::string& ID,
* See examples in sample_nodes directory.
*/

// NOLINTBEGIN(cppcoreguidelines-macro-usage,bugprone-macro-parentheses)
#define BT_REGISTER_NODES(factory) \
BTCPP_EXPORT void BT_RegisterNodesFromPlugin(BT::BehaviorTreeFactory& factory)
// NOLINTEND(cppcoreguidelines-macro-usage,bugprone-macro-parentheses)

constexpr const char* PLUGIN_SYMBOL = "BT_RegisterNodesFromPlugin";

Expand Down
2 changes: 1 addition & 1 deletion include/behaviortree_cpp/bt_parser.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2023 Davide Faconti - All Rights Reserved
/* Copyright (C) 2023-2025 Davide Faconti - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
Expand Down
Loading
Loading