Bug leads to crash program when using .set<T>() and then apply_visitor()

Open
#152 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
38/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
cpp
Domain
tooling

Research direction

Compile and run the C++ reproducer from the issue, then inspect the implementations of set() and apply_visitor(). Done means the example completes without crashing and the visitor handles the stored string and float values.

Written by the indexing model from the issue text.

Description

#include
#include <mapbox/variant.hpp>
#include <unordered_map>
using namespace std;
using namespace mapbox::util;

// Forward declaration
struct HPArray;
struct HPTable;
using HPVariant = variant<string,float,recursive_wrapper>;

struct HPArray{
template <typename ...Args>
HPArray(Args ...args){
values.emplace(std::forward(args)...);
}
unordered_map<int,HPVariant> values;
};

struct Visitor{

void operator()(const string &str){
    cout << str <<endl;;
}

void operator()(const float &value){
    cout << value <<endl;
}

void operator()(HPArray array){
    for (size_t i = 0; i < array.values.size(); i++)
    {
        apply_visitor(*this,array.values[i]);
    }
}

};

int main()
{
HPArray ar;
ar.values[0] = HPVariant("String");
ar.values[1] = 2.0f;

HPVariant var;
var.set<HPArray>(ar);
Visitor visitor;
apply_visitor(visitor,var);
return 0;

}

Dominant language
C++
Stars
384
Forks
96
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mapbox/variant

All issues in mapbox/variant

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.