cxxopts
cxxopts copied to clipboard
Visual Studio runtime assert when iterating parsed options
If you implement iteration of parsed options (like in the example code) and build under Visual Studio, there will be a Debug runtime assert when attempting to access the first key/value pair.
The assert message is Expression: vector iterators incompatible
We verified this problem under VS2017 and VS2022. It does not happen with Xcode 13 (Apple clang version 13.1.6) or clang version 10.0.0-4ubuntu under Linux.
You can reproduce this issue by building and running the example
target from the latest master (git hash ab1dc0f at the time of this writing). The assert happens on line number 93 of example.cpp
.
Thanks in advance for any help with this problem.
Here's a screenshot of the assert:

I think I know what's going on, it seems like visual studio's standard library does an extra check that two iterators point to the same container. I'll try to come up with a fix.
Checking in to see if there's any news on this issue. Thanks in advance.
Not yet, I'll try to get to it soon.
Any word on this issue?
Note that it's not critical because we've worked around it for now. But it would be nice to see it fixed properly.
Thanks in advance for your help.
Not yet sorry. I'll try to get to it soon.
Can you try the above commit to check if it is fixed?
Thanks for trying to fix this. Unfortunately I'm still seeing problems.
I can't reproduce the original problem because the example returns an error:
error parsing options: Argument '' failed to parse
This is new behavior, so I can't tell if the original problem is fixed or not.
After that I tried running options_test.exe
, which fails with a similar assert, originating from line number 1594 of cxxopts.hpp
.

The branch that I checked out was "fix_iter_access" (commit 65b4e91f). Hopefully that's the correct branch.
That's the right branch. I'll have another look at that.
I've pushed a fix for the example, and tried to fix the problem from the tests. Can you try both again?