diff --git a/include/fkYAML/detail/conversions/from_node.hpp b/include/fkYAML/detail/conversions/from_node.hpp index 50b0df0a..28997654 100644 --- a/include/fkYAML/detail/conversions/from_node.hpp +++ b/include/fkYAML/detail/conversions/from_node.hpp @@ -218,7 +218,7 @@ inline void from_node(const BasicNodeType& n, FloatType& f) throw exception("Floating point value overflow detected."); } - f = tmp_float; + f = static_cast(tmp_float); } /** diff --git a/include/fkYAML/detail/input/lexical_analyzer.hpp b/include/fkYAML/detail/input/lexical_analyzer.hpp index 709e33f9..2799494a 100644 --- a/include/fkYAML/detail/input/lexical_analyzer.hpp +++ b/include/fkYAML/detail/input/lexical_analyzer.hpp @@ -122,12 +122,14 @@ class lexical_analyzer { case ' ': break; - case '\r': - if (m_input_handler.get_next() == '\n') + case '\r': { + char_int_type next = m_input_handler.get_next(); + if (next == '\n') { m_input_handler.get_next(); } return m_last_token_type = lexical_token_t::MAPPING_BLOCK_PREFIX; + } case '\n': m_input_handler.get_next(); return m_last_token_type = lexical_token_t::MAPPING_BLOCK_PREFIX; @@ -153,7 +155,7 @@ class lexical_analyzer m_input_handler.get_next(); break; } - m_value_buffer.push_back(next); + m_value_buffer.push_back(char_traits_type::to_char_type(next)); } return m_last_token_type = lexical_token_t::ANCHOR_PREFIX; } @@ -171,7 +173,7 @@ class lexical_analyzer m_input_handler.get_next(); break; } - m_value_buffer.push_back(next); + m_value_buffer.push_back(char_traits_type::to_char_type(next)); } return m_last_token_type = lexical_token_t::ALIAS_PREFIX; } @@ -180,8 +182,9 @@ class lexical_analyzer return m_last_token_type = lexical_token_t::COMMENT_PREFIX; case '%': // directive prefix return m_last_token_type = scan_directive(); - case '-': - if (!m_input_handler.test_next_char(' ')) + case '-': { + bool is_next_space = m_input_handler.test_next_char(' '); + if (!is_next_space) { return m_last_token_type = scan_number(); } @@ -191,6 +194,7 @@ class lexical_analyzer m_input_handler.get_next(); return m_last_token_type = lexical_token_t::SEQUENCE_BLOCK_PREFIX; + } case '[': // sequence flow begin m_input_handler.get_next(); return m_last_token_type = lexical_token_t::SEQUENCE_FLOW_BEGIN; @@ -212,12 +216,13 @@ class lexical_analyzer case '\'': return m_last_token_type = scan_string(); case '~': - m_value_buffer = current; + m_value_buffer = char_traits_type::to_char_type(current); return m_last_token_type = lexical_token_t::NULL_VALUE; case '+': return m_last_token_type = scan_number(); case '.': { - if (m_input_handler.get_range(4, m_value_buffer) == end_of_input) + char_int_type ret = m_input_handler.get_range(4, m_value_buffer); + if (ret == end_of_input) { return m_last_token_type = scan_string(); } @@ -240,7 +245,8 @@ class lexical_analyzer case 'f': { // YAML specifies that only these words represent the boolean value `false`. // See "10.3.2. Tag Resolution" section in https://yaml.org/spec/1.2.2/ - if (m_input_handler.get_range(5, m_value_buffer) == end_of_input) + char_int_type ret = m_input_handler.get_range(5, m_value_buffer); + if (ret == end_of_input) { return m_last_token_type = scan_string(); } @@ -264,7 +270,8 @@ class lexical_analyzer // YAML specifies that these words and a tilde represent a null value. // Tildes are already checked above, so no check is needed here. // See "10.3.2. Tag Resolution" section in https://yaml.org/spec/1.2.2/ - if (m_input_handler.get_range(4, m_value_buffer) == end_of_input) + char_int_type ret = m_input_handler.get_range(4, m_value_buffer); + if (ret == end_of_input) { return m_last_token_type = scan_string(); } @@ -287,7 +294,8 @@ class lexical_analyzer case 't': { // YAML specifies that only these words represent the boolean value `true`. // See "10.3.2. Tag Resolution" section in https://yaml.org/spec/1.2.2/ - if (m_input_handler.get_range(4, m_value_buffer) == end_of_input) + char_int_type ret = m_input_handler.get_range(4, m_value_buffer); + if (ret == end_of_input) { return m_last_token_type = scan_string(); } @@ -495,19 +503,19 @@ class lexical_analyzer { throw fkyaml::exception("Invalid YAML major version found."); } - m_value_buffer.push_back(m_input_handler.get_current()); + m_value_buffer.push_back(char_traits_type::to_char_type(m_input_handler.get_current())); if (m_input_handler.get_next() != '.') { throw fkyaml::exception("A period must be followed after the YAML major version."); } - m_value_buffer.push_back(m_input_handler.get_current()); + m_value_buffer.push_back(char_traits_type::to_char_type(m_input_handler.get_current())); switch (m_input_handler.get_next()) { case '1': case '2': - m_value_buffer.push_back(m_input_handler.get_current()); + m_value_buffer.push_back(char_traits_type::to_char_type(m_input_handler.get_current())); break; case '0': case '3': @@ -548,14 +556,14 @@ class lexical_analyzer switch (current) { case '-': - m_value_buffer.push_back(current); + m_value_buffer.push_back(char_traits_type::to_char_type(current)); ret = scan_negative_number(); break; case '+': ret = scan_decimal_number(); break; case '0': - m_value_buffer.push_back(current); + m_value_buffer.push_back(char_traits_type::to_char_type(current)); ret = scan_number_after_zero_at_first(); break; case '1': @@ -567,7 +575,7 @@ class lexical_analyzer case '7': case '8': case '9': - m_value_buffer.push_back(current); + m_value_buffer.push_back(char_traits_type::to_char_type(current)); ret = scan_decimal_number(); break; default: // LCOV_EXCL_LINE @@ -601,11 +609,12 @@ class lexical_analyzer if (std::isdigit(next)) { - m_value_buffer.push_back(next); + m_value_buffer.push_back(char_traits_type::to_char_type(next)); return scan_decimal_number(); } - if (m_input_handler.get_range(4, m_value_buffer) != end_of_input) + char_int_type ret = m_input_handler.get_range(4, m_value_buffer); + if (ret != end_of_input) { try { @@ -634,7 +643,7 @@ class lexical_analyzer switch (next) { case '.': - m_value_buffer.push_back(next); + m_value_buffer.push_back(char_traits_type::to_char_type(next)); return scan_decimal_number_after_decimal_point(); case 'o': // Do not store 'o' since std::strtoull does not support "0o" but "0" as the prefix for octal numbers. @@ -642,7 +651,7 @@ class lexical_analyzer // See "10.3.2. Tag Resolution" section in https://yaml.org/spec/1.2.2/ return scan_octal_number(); case 'x': - m_value_buffer.push_back(next); + m_value_buffer.push_back(char_traits_type::to_char_type(next)); return scan_hexadecimal_number(); default: return lexical_token_t::INTEGER_VALUE; @@ -660,7 +669,7 @@ class lexical_analyzer if (std::isdigit(next)) { - m_value_buffer.push_back(next); + m_value_buffer.push_back(char_traits_type::to_char_type(next)); scan_decimal_number(); return lexical_token_t::FLOAT_NUMBER_VALUE; } @@ -678,12 +687,12 @@ class lexical_analyzer char_int_type next = m_input_handler.get_next(); if (next == '+' || next == '-') { - m_value_buffer.push_back(next); + m_value_buffer.push_back(char_traits_type::to_char_type(next)); scan_decimal_number_after_sign(); } else if (std::isdigit(next)) { - m_value_buffer.push_back(next); + m_value_buffer.push_back(char_traits_type::to_char_type(next)); scan_decimal_number(); } else @@ -704,7 +713,7 @@ class lexical_analyzer if (std::isdigit(next)) { - m_value_buffer.push_back(next); + m_value_buffer.push_back(char_traits_type::to_char_type(next)); return scan_decimal_number(); } @@ -722,24 +731,25 @@ class lexical_analyzer if (std::isdigit(next)) { - m_value_buffer.push_back(next); + m_value_buffer.push_back(char_traits_type::to_char_type(next)); return scan_decimal_number(); } if (next == '.') { - if (m_value_buffer.find(next) != string_type::npos) // NOLINT(abseil-string-find-str-contains) + // NOLINTNEXTLINE(abseil-string-find-str-contains) + if (m_value_buffer.find(char_traits_type::to_char_type(next)) != string_type::npos) { // TODO: support this use case (e.g. version info like 1.0.0) throw fkyaml::exception("Multiple decimal points found in a token."); } - m_value_buffer.push_back(next); + m_value_buffer.push_back(char_traits_type::to_char_type(next)); return scan_decimal_number_after_decimal_point(); } if (next == 'e' || next == 'E') { - m_value_buffer.push_back(next); + m_value_buffer.push_back(char_traits_type::to_char_type(next)); return scan_decimal_number_after_exponent(); } @@ -756,7 +766,7 @@ class lexical_analyzer char_int_type next = m_input_handler.get_next(); if ('0' <= next && next <= '7') { - m_value_buffer.push_back(next); + m_value_buffer.push_back(char_traits_type::to_char_type(next)); scan_octal_number(); } return lexical_token_t::INTEGER_VALUE; @@ -772,7 +782,7 @@ class lexical_analyzer char_int_type next = m_input_handler.get_next(); if (std::isxdigit(next)) { - m_value_buffer.push_back(next); + m_value_buffer.push_back(char_traits_type::to_char_type(next)); scan_hexadecimal_number(); } return lexical_token_t::INTEGER_VALUE; @@ -818,7 +828,7 @@ class lexical_analyzer { return lexical_token_t::STRING_VALUE; } - m_value_buffer.push_back(current); + m_value_buffer.push_back(char_traits_type::to_char_type(current)); continue; } @@ -836,7 +846,7 @@ class lexical_analyzer } // if the target is a single-quoted string token. - m_value_buffer.push_back(current); + m_value_buffer.push_back(char_traits_type::to_char_type(current)); continue; } @@ -850,9 +860,10 @@ class lexical_analyzer // If single quotation marks are repeated twice in a single-quoted string token. they are considered as // an escaped single quotation mark. - if (m_input_handler.test_next_char('\'')) + bool is_next_single_quote = m_input_handler.test_next_char('\''); + if (is_next_single_quote) { - m_value_buffer.push_back(m_input_handler.get_next()); + m_value_buffer.push_back(char_traits_type::to_char_type(m_input_handler.get_next())); continue; } @@ -865,7 +876,7 @@ class lexical_analyzer // Just regard a colon as a character if surrounded by quotation marks. if (needs_last_double_quote || needs_last_single_quote) { - m_value_buffer.push_back(current); + m_value_buffer.push_back(char_traits_type::to_char_type(current)); continue; } @@ -875,7 +886,7 @@ class lexical_analyzer // A colon as a key separator must be followed by a space or a newline code. if (next != ' ' && next != '\r' && next != '\n') { - m_value_buffer.push_back(current); + m_value_buffer.push_back(char_traits_type::to_char_type(current)); continue; } @@ -895,7 +906,7 @@ class lexical_analyzer // Just regard a comma as a character if surrounded by quotation marks. if (needs_last_double_quote || needs_last_single_quote) { - m_value_buffer.push_back(current); + m_value_buffer.push_back(char_traits_type::to_char_type(current)); continue; } @@ -908,7 +919,7 @@ class lexical_analyzer // just regard a right square bracket as a character if surrounded by quotation marks. if (needs_last_double_quote || needs_last_single_quote) { - m_value_buffer.push_back(current); + m_value_buffer.push_back(char_traits_type::to_char_type(current)); continue; } @@ -921,7 +932,7 @@ class lexical_analyzer // just regard a right curly brace as a character if surrounded by quotation marks. if (needs_last_double_quote || needs_last_single_quote) { - m_value_buffer.push_back(current); + m_value_buffer.push_back(char_traits_type::to_char_type(current)); continue; } @@ -1018,7 +1029,7 @@ class lexical_analyzer // Handle ASCII characters except control characters. if (current <= 0x7E) { - m_value_buffer.push_back(current); + m_value_buffer.push_back(char_traits_type::to_char_type(current)); continue; } @@ -1056,7 +1067,7 @@ class lexical_analyzer case 0x08: throw fkyaml::exception("Control character U+0008 (BS) must be escaped to \\b or \\u0008."); case 0x09: // HT - m_value_buffer.push_back(c); + m_value_buffer.push_back(char_traits_type::to_char_type(c)); break; // 0x0A(LF) has already been handled above. case 0x0B: diff --git a/include/fkYAML/detail/iterator.hpp b/include/fkYAML/detail/iterator.hpp index e507a8db..4f10101b 100644 --- a/include/fkYAML/detail/iterator.hpp +++ b/include/fkYAML/detail/iterator.hpp @@ -172,7 +172,7 @@ class iterator * * @param other An iterator object to be copied with. */ - iterator(const iterator& other) noexcept // NOLINT(bugprone-exception-escape) + iterator(const iterator& other) : m_inner_iterator_type(other.m_inner_iterator_type) { switch (m_inner_iterator_type) @@ -193,7 +193,7 @@ class iterator * * @param other An iterator object to be moved from. */ - iterator(iterator&& other) noexcept // NOLINT(bugprone-exception-escape) + iterator(iterator&& other) : m_inner_iterator_type(other.m_inner_iterator_type) { switch (m_inner_iterator_type) @@ -218,7 +218,7 @@ class iterator * @param rhs An iterator object to be copied with. * @return iterator& Reference to this iterator object. */ - iterator& operator=(const iterator& rhs) noexcept // NOLINT(cert-oop54-cpp,bugprone-exception-escape) + iterator& operator=(const iterator& rhs) // NOLINT(cert-oop54-cpp) { if (&rhs == this) { @@ -247,7 +247,7 @@ class iterator * @param rhs An iterator object to be moved from. * @return iterator& Reference to this iterator object. */ - iterator& operator=(iterator&& rhs) noexcept // NOLINT(bugprone-exception-escape) + iterator& operator=(iterator&& rhs) { if (&rhs == this) { @@ -275,7 +275,7 @@ class iterator * * @return pointer A pointer to the BasicNodeType object internally referenced by the actual iterator object. */ - pointer operator->() noexcept // NOLINT(bugprone-exception-escape) + pointer operator->() { switch (m_inner_iterator_type) { @@ -293,7 +293,7 @@ class iterator * * @return reference Reference to the Node object internally referenced by the actual iterator object. */ - reference operator*() noexcept // NOLINT(bugprone-exception-escape) + reference operator*() { switch (m_inner_iterator_type) { @@ -312,7 +312,7 @@ class iterator * @param i The difference from this Iterator object with which it moves forward. * @return Iterator& Reference to this Iterator object. */ - iterator& operator+=(difference_type i) noexcept // NOLINT(bugprone-exception-escape) + iterator& operator+=(difference_type i) { switch (m_inner_iterator_type) { @@ -346,7 +346,7 @@ class iterator * * @return iterator& Reference to this iterator object. */ - iterator& operator++() noexcept // NOLINT(bugprone-exception-escape) + iterator& operator++() { switch (m_inner_iterator_type) { @@ -380,7 +380,7 @@ class iterator * @param i The difference from this iterator object with which it moves backward. * @return iterator& Reference to this iterator object. */ - iterator& operator-=(difference_type i) noexcept // NOLINT(bugprone-exception-escape) + iterator& operator-=(difference_type i) { return operator+=(-i); } @@ -403,7 +403,7 @@ class iterator * * @return iterator& Reference to this iterator object. */ - iterator& operator--() noexcept // NOLINT(bugprone-exception-escape) + iterator& operator--() { switch (m_inner_iterator_type) { @@ -563,7 +563,7 @@ class iterator * * @return reference A reference to the YAML node for the current iterator. */ - reference value() noexcept // NOLINT(bugprone-exception-escape) + reference value() { return operator*(); } diff --git a/include/fkYAML/detail/output/serializer.hpp b/include/fkYAML/detail/output/serializer.hpp index 9f6ef9c1..82e3c258 100644 --- a/include/fkYAML/detail/output/serializer.hpp +++ b/include/fkYAML/detail/output/serializer.hpp @@ -77,7 +77,8 @@ class basic_serializer { insert_indentation(cur_indent, str); str += "-"; - if (seq_item.is_scalar()) + bool is_scalar = seq_item.is_scalar(); + if (is_scalar) { str += " "; serialize_node(seq_item, cur_indent, str); @@ -95,7 +96,8 @@ class basic_serializer { insert_indentation(cur_indent, str); serialize_key(itr.key(), str); - if (itr->is_scalar()) + bool is_scalar = itr->is_scalar(); + if (is_scalar) { str += " "; serialize_node(*itr, cur_indent, str); diff --git a/include/fkYAML/node.hpp b/include/fkYAML/node.hpp index 592e4086..e48c0a35 100644 --- a/include/fkYAML/node.hpp +++ b/include/fkYAML/node.hpp @@ -358,7 +358,7 @@ class basic_node * * @param[in] rhs A basic_node object to be moved from. */ - basic_node(basic_node&& rhs) noexcept // NOLINT(bugprone-exception-escape) + basic_node(basic_node&& rhs) noexcept : m_node_type(rhs.m_node_type), m_yaml_version_type(rhs.m_yaml_version_type), m_anchor_name(rhs.m_anchor_name) @@ -396,8 +396,6 @@ class basic_node m_node_value.p_string = rhs.m_node_value.p_string; rhs.m_node_value.p_string = nullptr; break; - default: // LCOV_EXCL_LINE - throw fkyaml::exception("Unsupported node value type."); // LCOV_EXCL_LINE } rhs.m_node_type = node_t::NULL_OBJECT; diff --git a/test/unit_test/CMakeLists.txt b/test/unit_test/CMakeLists.txt index 2522d0ea..022d5f34 100644 --- a/test/unit_test/CMakeLists.txt +++ b/test/unit_test/CMakeLists.txt @@ -21,8 +21,12 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Od") elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wno-terminate") + # necessary to build iterator class test. + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-self-move") elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-c++98-compat -Wno-c++98-compat-pedantic") + # necessary to build iterator class test. + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-self-assign-overloaded -Wno-self-move") endif() # determine C++ standard used in unit test app. diff --git a/test/unit_test/test_node_class.cpp b/test/unit_test/test_node_class.cpp index de22811c..fca6b458 100644 --- a/test/unit_test/test_node_class.cpp +++ b/test/unit_test/test_node_class.cpp @@ -1547,9 +1547,9 @@ TEST_CASE("NodeClassTest_GetValueTest", "[NodeClassTest]") SECTION("test for float number values.") { - REQUIRE(fabsf(node.get_value() - 3.14) < FLT_EPSILON); - REQUIRE(fabsf(node.get_value() - 3.14) < DBL_EPSILON); - REQUIRE(fabsf(node.get_value() - 3.14) < LDBL_EPSILON); + REQUIRE(std::abs(node.get_value() - 3.14) < std::numeric_limits::epsilon()); + REQUIRE(std::abs(node.get_value() - 3.14) < std::numeric_limits::epsilon()); + REQUIRE(std::abs(node.get_value() - 3.14) < std::numeric_limits::epsilon()); } SECTION("test for non-float-number values.")