Skip to content

Commit

Permalink
partially fix clang compilation (jbeder#893)
Browse files Browse the repository at this point in the history
* partially fix clang compilation

Missing header and mistaken algorithm usage.

Also removed it name from range loops. It's not correct.

Signed-off-by: Rosen Penev <[email protected]>

* run through clang's -Wrange-loop-analysis

Some range loops should not use references as they need to copy.

Signed-off-by: Rosen Penev <[email protected]>

* manual range loop conversions

Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb authored Jun 15, 2020
1 parent 6387cbc commit b2cd008
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 35 deletions.
32 changes: 18 additions & 14 deletions include/yaml-cpp/node/convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ template <typename K, typename V, typename C, typename A>
struct convert<std::map<K, V, C, A>> {
static Node encode(const std::map<K, V, C, A>& rhs) {
Node node(NodeType::Map);
for (const auto& it : rhs)
node.force_insert(it.first, it.second);
for (const auto& element : rhs)
node.force_insert(element.first, element.second);
return node;
}

Expand All @@ -235,12 +235,12 @@ struct convert<std::map<K, V, C, A>> {
return false;

rhs.clear();
for (const auto& it : node)
for (const auto& element : node)
#if defined(__GNUC__) && __GNUC__ < 4
// workaround for GCC 3:
rhs[it.first.template as<K>()] = it.second.template as<V>();
rhs[element.first.template as<K>()] = element.second.template as<V>();
#else
rhs[it.first.as<K>()] = it.second.as<V>();
rhs[element.first.as<K>()] = element.second.as<V>();
#endif
return true;
}
Expand All @@ -251,7 +251,8 @@ template <typename T, typename A>
struct convert<std::vector<T, A>> {
static Node encode(const std::vector<T, A>& rhs) {
Node node(NodeType::Sequence);
std::copy(rhs.begin(), rhs.end(), std::back_inserter(rhs));
for (const auto& element : rhs)
node.push_back(element);
return node;
}

Expand All @@ -260,12 +261,12 @@ struct convert<std::vector<T, A>> {
return false;

rhs.clear();
for (const auto& it : node)
for (const auto& element : node)
#if defined(__GNUC__) && __GNUC__ < 4
// workaround for GCC 3:
rhs.push_back(it.template as<T>());
rhs.push_back(element.template as<T>());
#else
rhs.push_back(it.as<T>());
rhs.push_back(element.as<T>());
#endif
return true;
}
Expand All @@ -276,7 +277,8 @@ template <typename T, typename A>
struct convert<std::list<T,A>> {
static Node encode(const std::list<T,A>& rhs) {
Node node(NodeType::Sequence);
std::copy(rhs.begin(), rhs.end(), std::back_inserter(rhs));
for (const auto& element : rhs)
node.push_back(element);
return node;
}

Expand All @@ -285,12 +287,12 @@ struct convert<std::list<T,A>> {
return false;

rhs.clear();
for (const auto& it : node)
for (const auto& element : node)
#if defined(__GNUC__) && __GNUC__ < 4
// workaround for GCC 3:
rhs.push_back(it.template as<T>());
rhs.push_back(element.template as<T>());
#else
rhs.push_back(it.as<T>());
rhs.push_back(element.as<T>());
#endif
return true;
}
Expand All @@ -301,7 +303,9 @@ template <typename T, std::size_t N>
struct convert<std::array<T, N>> {
static Node encode(const std::array<T, N>& rhs) {
Node node(NodeType::Sequence);
std::copy(rhs.begin(), rhs.end(), std::back_inserter(rhs));
for (const auto& element : rhs) {
node.push_back(element);
}
return node;
}

Expand Down
2 changes: 1 addition & 1 deletion include/yaml-cpp/node/detail/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ inline node& node_data::get(const Key& key, shared_memory_holder pMemory) {
});

if (it != m_map.end()) {
return it->second;
return *it->second;
}

node& k = convert_to_node(key, pMemory);
Expand Down
8 changes: 4 additions & 4 deletions include/yaml-cpp/stlemitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ namespace YAML {
template <typename Seq>
inline Emitter& EmitSeq(Emitter& emitter, const Seq& seq) {
emitter << BeginSeq;
for (typename Seq::const_iterator it = seq.begin(); it != seq.end(); ++it)
emitter << *it;
for (const auto& emit : seq)
emitter << emit;
emitter << EndSeq;
return emitter;
}
Expand All @@ -41,8 +41,8 @@ template <typename K, typename V>
inline Emitter& operator<<(Emitter& emitter, const std::map<K, V>& m) {
typedef typename std::map<K, V> map;
emitter << BeginMap;
for (typename map::const_iterator it = m.begin(); it != m.end(); ++it)
emitter << Key << it->first << Value << it->second;
for (const auto& emit : m)
emitter << Key << emit.first << Value << emit.second;
emitter << EndMap;
return emitter;
}
Expand Down
1 change: 1 addition & 0 deletions src/node_data.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <algorithm>
#include <cassert>
#include <iterator>
#include <sstream>
Expand Down
22 changes: 10 additions & 12 deletions src/nodeevents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ void NodeEvents::Setup(const detail::node& node) {
return;

if (node.type() == NodeType::Sequence) {
for (const auto& it : node)
Setup(*it);
for (auto element : node)
Setup(*element);
} else if (node.type() == NodeType::Map) {
for (detail::const_node_iterator it = node.begin(); it != node.end();
++it) {
Setup(*it->first);
Setup(*it->second);
for (auto element : node) {
Setup(*element.first);
Setup(*element.second);
}
}
}
Expand Down Expand Up @@ -77,16 +76,15 @@ void NodeEvents::Emit(const detail::node& node, EventHandler& handler,
break;
case NodeType::Sequence:
handler.OnSequenceStart(Mark(), node.tag(), anchor, node.style());
for (const auto& it : node)
Emit(*it, handler, am);
for (auto element : node)
Emit(*element, handler, am);
handler.OnSequenceEnd();
break;
case NodeType::Map:
handler.OnMapStart(Mark(), node.tag(), anchor, node.style());
for (detail::const_node_iterator it = node.begin(); it != node.end();
++it) {
Emit(*it->first, handler, am);
Emit(*it->second, handler, am);
for (auto element : node) {
Emit(*element.first, handler, am);
Emit(*element.second, handler, am);
}
handler.OnMapEnd();
break;
Expand Down
5 changes: 2 additions & 3 deletions src/setting.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ class SettingChanges {
}

void restore() YAML_CPP_NOEXCEPT {
for (setting_changes::const_iterator it = m_settingChanges.begin();
it != m_settingChanges.end(); ++it)
(*it)->pop();
for (const auto& setting : m_settingChanges)
setting->pop();
}

void push(std::unique_ptr<SettingChangeBase> pSettingChange) {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/load_node_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ TEST(NodeTest, IncompleteJson) {
{"JSON map without end brace", "{\"access\":\"abc\"",
ErrorMsg::END_OF_MAP_FLOW},
};
for (const ParserExceptionTestCase test : tests) {
for (const ParserExceptionTestCase& test : tests) {
try {
Load(test.input);
FAIL() << "Expected exception " << test.expected_exception << " for "
Expand Down

0 comments on commit b2cd008

Please sign in to comment.