From 1a9800bdb2224ceb778614132638513ea4a775cc Mon Sep 17 00:00:00 2001 From: Daniel Burr Date: Sun, 10 May 2020 18:25:42 +0200 Subject: [PATCH 1/2] Fix warning preventing compilation with gcc 8.2.0 when -Werror is enabled (due to -Werror=switch-default and -Werror=float-equal) --- include/yaml-cpp/emitter.h | 4 ++-- include/yaml-cpp/node/detail/impl.h | 2 ++ include/yaml-cpp/node/detail/node_iterator.h | 6 ++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/yaml-cpp/emitter.h b/include/yaml-cpp/emitter.h index 6f142b011..40e5d6a2b 100644 --- a/include/yaml-cpp/emitter.h +++ b/include/yaml-cpp/emitter.h @@ -165,10 +165,10 @@ inline Emitter& Emitter::WriteStreamable(T value) { special = true; stream << ".nan"; } else if (std::numeric_limits::has_infinity) { - if (value == std::numeric_limits::infinity()) { + if (std::isinf(value) && value > 0) { special = true; stream << ".inf"; - } else if (value == -std::numeric_limits::infinity()) { + } else if (std::isinf(value) && value < 0) { special = true; stream << "-.inf"; } diff --git a/include/yaml-cpp/node/detail/impl.h b/include/yaml-cpp/node/detail/impl.h index 46615a9f4..a776d752c 100644 --- a/include/yaml-cpp/node/detail/impl.h +++ b/include/yaml-cpp/node/detail/impl.h @@ -115,6 +115,7 @@ inline node* node_data::get(const Key& key, return pNode; return NULL; case NodeType::Scalar: + default: throw BadSubscript(key); } @@ -143,6 +144,7 @@ inline node& node_data::get(const Key& key, shared_memory_holder pMemory) { convert_to_map(pMemory); break; case NodeType::Scalar: + default: throw BadSubscript(key); } diff --git a/include/yaml-cpp/node/detail/node_iterator.h b/include/yaml-cpp/node/detail/node_iterator.h index 088090fe7..11768f7ec 100644 --- a/include/yaml-cpp/node/detail/node_iterator.h +++ b/include/yaml-cpp/node/detail/node_iterator.h @@ -111,6 +111,8 @@ class node_iterator_base return m_seqIt == rhs.m_seqIt; case iterator_type::Map: return m_mapIt == rhs.m_mapIt; + default: + break; } return true; } @@ -131,6 +133,8 @@ class node_iterator_base ++m_mapIt; m_mapIt = increment_until_defined(m_mapIt); break; + default: + break; } return *this; } @@ -149,6 +153,8 @@ class node_iterator_base return value_type(**m_seqIt); case iterator_type::Map: return value_type(*m_mapIt->first, *m_mapIt->second); + default: + break; } return value_type(); } From 994c84160d7f1771c4a451b280f1148bfdea3975 Mon Sep 17 00:00:00 2001 From: Daniel Burr Date: Sun, 10 May 2020 18:33:15 +0200 Subject: [PATCH 2/2] Backport upstream fix --- include/yaml-cpp/emitter.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/include/yaml-cpp/emitter.h b/include/yaml-cpp/emitter.h index 40e5d6a2b..2add9ee07 100644 --- a/include/yaml-cpp/emitter.h +++ b/include/yaml-cpp/emitter.h @@ -164,13 +164,12 @@ inline Emitter& Emitter::WriteStreamable(T value) { std::isnan(value)) { special = true; stream << ".nan"; - } else if (std::numeric_limits::has_infinity) { - if (std::isinf(value) && value > 0) { - special = true; - stream << ".inf"; - } else if (std::isinf(value) && value < 0) { - special = true; + } else if (std::numeric_limits::has_infinity && std::isinf(value)) { + special = true; + if (std::signbit(value)) { stream << "-.inf"; + } else { + stream << ".inf"; } } }