-
Notifications
You must be signed in to change notification settings - Fork 361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
App::add_set() can crash your application in some cases when printing the help #170
Comments
The reference is kept so that you can modify the set later on as in #114. You can fix it in this case: Parser.add_set("-a", SomeVar, std::move(SomeSet), "Some description."); (You'll see there is a && version that does a copy). Normally, you have to keep a reference to SomeVar anyway, so the same is true for SomeSet. |
I think the design that you currently have is somewhat problematic as it is dangerous by default, i.e. you have to use
|
I like option 2. Option 1 can't be done using the current design - all options are the same. At some point (see the idea board), options could be implemented as Option, and then option 1 would be possible. |
I have come across the same issue or similar issues. I would agree with @SkyToGround the function as is makes it easy to get into trouble. I think instead of option 2, I would just suggest a member function of the Option to modify the set and always take by const reference. That function would update the callback with a new lambda function just like the add_set function and just keep the same names. |
So, the options are currently:
So I think I will either leave it as is till 1.8 or take option 3 then hopefully still fix it properly in 1.8. |
Number 1 would address #12, as well, I believe. |
In
App::add_set()
, theconst std::set<std::string> &options
argument will likely crash your application when used as follows:The reason for this is that
add_set()
uses a reference tooptions
when creating a lambda. When this lambda is called at a later point,SomeSet
has been allocated. Instead, the possible options should be copied.The text was updated successfully, but these errors were encountered: