Skip to content

Commit f3e866e

Browse files
committed
fix warnings
1 parent a2c229a commit f3e866e

File tree

8 files changed

+34
-59
lines changed

8 files changed

+34
-59
lines changed

.clang-tidy

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,14 @@ Checks: [
1313
"-bugprone-easily-swappable-parameters",
1414
"-bugprone-narrowing-conversions",
1515
"-cppcoreguidelines-avoid-c-arrays",
16-
"-cppcoreguidelines-avoid-const-or-ref-data-members",
1716
"-cppcoreguidelines-avoid-magic-numbers",
1817
"-cppcoreguidelines-avoid-non-const-global-variables",
19-
"-cppcoreguidelines-narrowing-conversions",
20-
"-cppcoreguidelines-owning-memory",
2118
"-cppcoreguidelines-pro-bounds-array-to-pointer-decay",
2219
"-cppcoreguidelines-pro-bounds-constant-array-index",
2320
"-cppcoreguidelines-pro-bounds-pointer-arithmetic",
24-
"-cppcoreguidelines-pro-type-const-cast",
25-
"-cppcoreguidelines-pro-type-member-init",
2621
"-cppcoreguidelines-pro-type-union-access",
2722
"-cppcoreguidelines-pro-type-vararg",
28-
"-cppcoreguidelines-use-default-member-init",
29-
"-misc-no-recursion",
30-
"-modernize-avoid-c-arrays",
31-
"-modernize-use-emplace",
32-
"-performance-avoid-const-params",
33-
"-performance-avoid-endl",
34-
"-performance-noexcept-move-constructor",
35-
"-readability-magic-numbers"
23+
"-misc-no-recursion"
3624
]
3725

3826

include/behaviortree_cpp/actions/sleep_node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class SleepNode : public StatefulActionNode
3535

3636
private:
3737
TimerQueue<> timer_;
38-
uint64_t timer_id_;
38+
uint64_t timer_id_ = 0;
3939

4040
std::atomic_bool timer_waiting_ = false;
4141
std::mutex delay_mutex_;

include/behaviortree_cpp/utils/convert_impl.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,17 @@ void convertNumber(const SRC& source, DST& target)
157157
// these conversions are always safe:
158158
// - same type
159159
// - float -> double
160-
// - conversion to bool
161-
if constexpr(is_same<SRC, DST>() || (is_same<SRC, float>() && is_same<DST, double>()) ||
162-
(is_convertible_to_bool<SRC>() && is_same<DST, bool>()))
160+
if constexpr(is_same<SRC, DST>() || (is_same<SRC, float>() && is_same<DST, double>()))
163161
{
164162
// No check needed
165163
target = static_cast<DST>(source);
166164
}
165+
// conversion to bool requires validation (only 0 and 1 allowed)
166+
else if constexpr(is_convertible_to_bool<SRC>() && is_same<DST, bool>())
167+
{
168+
checkLowerLimit<SRC, DST>(source);
169+
target = static_cast<DST>(source);
170+
}
167171
else if constexpr(both_integers)
168172
{
169173
if constexpr(sizeof(SRC) == sizeof(DST) && !is_signed<SRC>() && is_signed<DST>())

include/behaviortree_cpp/utils/simple_string.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ namespace SafeAny
1818
class SimpleString
1919
{
2020
public:
21-
SimpleString() = default;
21+
SimpleString()
22+
{
23+
_storage.soo.data[0] = '\0';
24+
}
2225

2326
SimpleString(const std::string& str) : SimpleString(str.data(), str.size())
2427
{}

src/behavior_tree.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ void printTreeRecursively(const TreeNode* root_node, std::ostream& stream)
9898
stream << "----------------" << std::endl;
9999
}
100100

101-
namespace
102-
{
103-
void buildSerializedStatusSnapshot(TreeNode* root_node,
101+
void buildSerializedStatusSnapshot(const TreeNode* root_node,
104102
SerializedTreeStatus& serialized_buffer)
105103
{
106104
serialized_buffer.clear();
@@ -112,7 +110,6 @@ void buildSerializedStatusSnapshot(TreeNode* root_node,
112110

113111
applyRecursiveVisitor(root_node, visitor);
114112
}
115-
} // namespace
116113

117114
int LibraryVersionNumber()
118115
{

src/blackboard.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const Any* Blackboard::getAny(const std::string& key) const
4444

4545
Any* Blackboard::getAny(const std::string& key)
4646
{
47+
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
4748
return const_cast<Any*>(getAnyLocked(key).get());
4849
}
4950

@@ -322,6 +323,7 @@ Blackboard::Entry& Blackboard::Entry::operator=(const Entry& other)
322323
Blackboard* BT::Blackboard::rootBlackboard()
323324
{
324325
auto bb = static_cast<const Blackboard&>(*this).rootBlackboard();
326+
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
325327
return const_cast<Blackboard*>(bb);
326328
}
327329

src/loggers/groot2_publisher.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ std::array<char, 16> CreateRandomUUID()
3737
std::random_device rd;
3838
std::mt19937 gen(rd());
3939
std::uniform_int_distribution<uint32_t> dist;
40-
std::array<char, 16> out;
40+
std::array<char, 16> out{};
4141
char* bytes = out.data();
4242
for(int i = 0; i < 16; i += 4)
4343
{
4444
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
4545
*reinterpret_cast<uint32_t*>(bytes + i) = dist(gen);
4646
}
4747
// variant must be 10xxxxxx
48-
bytes[8] &= 0xBF;
49-
bytes[8] |= 0x80;
48+
bytes[8] &= static_cast<char>(0xBF);
49+
bytes[8] |= static_cast<char>(0x80);
5050

5151
// version must be 0100xxxx
5252
bytes[6] &= 0x4F;
@@ -100,7 +100,7 @@ struct Groot2Publisher::PImpl
100100

101101
std::atomic_bool recording = false;
102102
std::deque<Transition> transitions_buffer;
103-
std::chrono::microseconds recording_fist_time;
103+
std::chrono::microseconds recording_fist_time{};
104104

105105
std::thread heartbeat_thread;
106106

@@ -209,13 +209,13 @@ void Groot2Publisher::callback(Duration ts, const TreeNode& node, NodeStatus pre
209209

210210
if(new_status == NodeStatus::IDLE)
211211
{
212-
status = 10 + static_cast<char>(prev_status);
212+
status = static_cast<char>(10 + static_cast<int>(prev_status));
213213
}
214214
*(_p->status_buffermap.at(node.UID())) = status;
215215

216216
if(_p->recording)
217217
{
218-
Transition trans;
218+
Transition trans{};
219219
trans.node_uid = node.UID();
220220
trans.status = static_cast<uint8_t>(new_status);
221221
auto timestamp = ts - _p->recording_fist_time;

src/xml_parsing.cpp

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,15 @@ struct XMLParser::PImpl
118118
std::list<std::unique_ptr<XMLDocument> > opened_documents;
119119
std::map<std::string, const XMLElement*> tree_roots;
120120

121-
const BehaviorTreeFactory& factory;
121+
const BehaviorTreeFactory* factory = nullptr;
122122

123123
std::filesystem::path current_path;
124124
std::map<std::string, SubtreeModel> subtree_models;
125125

126-
int suffix_count;
126+
int suffix_count = 0;
127127

128128
explicit PImpl(const BehaviorTreeFactory& fact)
129-
: factory(fact), current_path(std::filesystem::current_path()), suffix_count(0)
129+
: factory(&fact), current_path(std::filesystem::current_path())
130130
{}
131131

132132
void clear()
@@ -162,7 +162,7 @@ XMLParser::~XMLParser()
162162

163163
void XMLParser::loadFromFile(const std::filesystem::path& filepath, bool add_includes)
164164
{
165-
_p->opened_documents.emplace_back(new XMLDocument());
165+
_p->opened_documents.push_back(std::make_unique<XMLDocument>());
166166

167167
XMLDocument* doc = _p->opened_documents.back().get();
168168
doc->LoadFile(filepath.string().c_str());
@@ -174,7 +174,7 @@ void XMLParser::loadFromFile(const std::filesystem::path& filepath, bool add_inc
174174

175175
void XMLParser::loadFromText(const std::string& xml_text, bool add_includes)
176176
{
177-
_p->opened_documents.emplace_back(new XMLDocument());
177+
_p->opened_documents.push_back(std::make_unique<XMLDocument>());
178178

179179
XMLDocument* doc = _p->opened_documents.back().get();
180180
doc->Parse(xml_text.c_str(), xml_text.size());
@@ -311,7 +311,7 @@ void XMLParser::PImpl::loadDocImpl(XMLDocument* doc, bool add_includes)
311311
file_path = current_path / file_path;
312312
}
313313

314-
opened_documents.emplace_back(new XMLDocument());
314+
opened_documents.push_back(std::make_unique<XMLDocument>());
315315
XMLDocument* next_doc = opened_documents.back().get();
316316

317317
// change current path to the included file for handling additional relative paths
@@ -327,7 +327,7 @@ void XMLParser::PImpl::loadDocImpl(XMLDocument* doc, bool add_includes)
327327

328328
// Collect the names of all nodes registered with the behavior tree factory
329329
std::unordered_map<std::string, BT::NodeType> registered_nodes;
330-
for(const auto& it : factory.manifests())
330+
for(const auto& it : factory->manifests())
331331
{
332332
registered_nodes.insert({ it.first, it.second.type });
333333
}
@@ -629,7 +629,7 @@ TreeNode::Ptr XMLParser::PImpl::createNodeFromXML(const XMLElement* element,
629629
{
630630
// This is the case of nodes like <MyCustomAction>
631631
// check if the factory has this name
632-
if(factory.builders().count(element_name) == 0)
632+
if(factory->builders().count(element_name) == 0)
633633
{
634634
throw RuntimeError(element_name, " is not a registered node");
635635
}
@@ -657,8 +657,8 @@ TreeNode::Ptr XMLParser::PImpl::createNodeFromXML(const XMLElement* element,
657657

658658
const TreeNodeManifest* manifest = nullptr;
659659

660-
auto manifest_it = factory.manifests().find(type_ID);
661-
if(manifest_it != factory.manifests().end())
660+
auto manifest_it = factory->manifests().find(type_ID);
661+
if(manifest_it != factory->manifests().end())
662662
{
663663
manifest = &manifest_it->second;
664664
}
@@ -758,7 +758,7 @@ TreeNode::Ptr XMLParser::PImpl::createNodeFromXML(const XMLElement* element,
758758
{
759759
config.input_ports = port_remap;
760760
new_node =
761-
factory.instantiateTreeNode(instance_name, toStr(NodeType::SUBTREE), config);
761+
factory->instantiateTreeNode(instance_name, toStr(NodeType::SUBTREE), config);
762762
auto subtree_node = dynamic_cast<SubTreeNode*>(new_node.get());
763763
subtree_node->setSubtreeID(type_ID);
764764
}
@@ -873,7 +873,7 @@ TreeNode::Ptr XMLParser::PImpl::createNodeFromXML(const XMLElement* element,
873873
}
874874
}
875875

876-
new_node = factory.instantiateTreeNode(instance_name, type_ID, config);
876+
new_node = factory->instantiateTreeNode(instance_name, type_ID, config);
877877
}
878878

879879
// add the pointer of this node to the parent
@@ -1517,25 +1517,6 @@ std::string writeTreeXSD(const BehaviorTreeFactory& factory)
15171517
return std::string(printer.CStr(), size_t(printer.CStrSize() - 1));
15181518
}
15191519

1520-
namespace
1521-
{
1522-
Tree buildTreeFromText(const BehaviorTreeFactory& factory, const std::string& text,
1523-
const Blackboard::Ptr& blackboard)
1524-
{
1525-
XMLParser parser(factory);
1526-
parser.loadFromText(text);
1527-
return parser.instantiateTree(blackboard);
1528-
}
1529-
1530-
Tree buildTreeFromFile(const BehaviorTreeFactory& factory, const std::string& filename,
1531-
const Blackboard::Ptr& blackboard)
1532-
{
1533-
XMLParser parser(factory);
1534-
parser.loadFromFile(filename);
1535-
return parser.instantiateTree(blackboard);
1536-
}
1537-
} // namespace
1538-
15391520
std::string WriteTreeToXML(const Tree& tree, bool add_metadata, bool add_builtin_models)
15401521
{
15411522
XMLDocument doc;

0 commit comments

Comments
 (0)