Skip to content

Removing option with a link causes an error #172

Closed
@OlivierHartmann

Description

@OlivierHartmann

Hello,

Thank you for this work.
I have found an issue while removing an option that has a link with another one.
Here is a minimalist example causing the bug:

#include <CLI/CLI.hpp>

int main(int argc, char **argv) {

    CLI::App app{"App to demonstrate a bug."};

    int foo, bar;
    auto foo_option = app.add_option("--foo,-f", foo, "An argument");
    app.add_option("--bar", bar, "Another argument")->excludes(foo_option);

    app.remove_option(foo_option);

    CLI11_PARSE(app, argc, argv);
}

Then when running with the "help" flag, we get the following error:

   terminate called after throwing an instance of 'std::bad_alloc'
     what():  std::bad_alloc
   Abandon (core dumped)

The solution can therefore simply be to delete the links at the same time as deleting the option.

Thank you

Olivier

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions