yaml-cpp icon indicating copy to clipboard operation
yaml-cpp copied to clipboard

Can't create a map with first key floating-point 0

Open ephere opened this issue 2 years ago • 3 comments

Here's a failing test:

TEST(NodeTest, CreateMapWithFloatingPoint0Key) {
  Node node;
  node[0.0] = 1.0;
  EXPECT_TRUE(node.IsMap());
}

It doesn't work because the specialization of get_idx in node/detail/impl.h is enabled on std::is_signed condition, which returns true for floating-point types, while the Key template parameter of get_idx is expected to be integral. The result is that get_idx succeeds and the node is converted to a sequence instead of a map, with the value added at index 0.

This can be fixed by adding && std::is_integral<Key>::value to the std::enable_if<std::is_signed<Key>::value> specialization of get_idx in node/detail/impl.h. I suppose the same same has to be done for the specialization of remove_idx in the same file.

ephere avatar Jan 24 '23 09:01 ephere

Sorry, I incorrectly posted this from my company's account.

ikolev21 avatar Jan 24 '23 10:01 ikolev21

Agreed, this is a bug, thank you! Feel free to submit a PR with that fix.

jbeder avatar Aug 10 '23 19:08 jbeder

Sorry, I haven't used GitHub for development yet, it will take time until I figure out how to submit PRs...

ikolev21 avatar Feb 23 '24 11:02 ikolev21