Skip to content

Uninitialized values of intermediate nodes #129

@ilya-talankin

Description

@ilya-talankin

If you add values along a multi-level path to the ptree, the values of the intermediate nodes remain uninitialized. The sample code is below

#include <boost/property_tree/ptree.hpp>
#include <iostream>

enum class NodeType
{
    Intermediate,
    Root,
    Leaf
};

using Tree = boost::property_tree::basic_ptree<std::string, NodeType>;

void Print(const Tree& tree, std::string_view name)
{
    const auto value = tree.get_value(NodeType::Intermediate);
    std::cout << "Name: " << name << ", value: " << static_cast<int>(value) << std::endl;
    for (const auto& [childName, subtree]: tree)
        Print(subtree, childName);
}

int main() {
    Tree tree;
    tree.add("Intermediate1.Intermediate2.Leaf", NodeType::Leaf);
    tree.put_value(NodeType::Root);
    Print(tree, "Root");
}

Compiled with boost 1.87 by x86-64 clang-18.1.0
Godbolt link
Possible output:

Name: Root, value: 1
Name: Intermediate1, value: 0
Name: Intermediate2, value: -249048016
Name: Leaf, value: 2

One of the correction options https://github.com/ilya-talankin/property_tree/pull/1/files

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions