cxxopts icon indicating copy to clipboard operation
cxxopts copied to clipboard

Visual Studio runtime assert when iterating parsed options

Open acronce opened this issue 2 years ago • 4 comments

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.

acronce avatar Aug 26 '22 00:08 acronce

Here's a screenshot of the assert:

Screen Shot 2022-08-25 at 4 49 12 PM

acronce avatar Aug 26 '22 00:08 acronce

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.

jarro2783 avatar Aug 28 '22 20:08 jarro2783

Checking in to see if there's any news on this issue. Thanks in advance.

acronce avatar Sep 10 '22 18:09 acronce

Not yet, I'll try to get to it soon.

jarro2783 avatar Sep 11 '22 21:09 jarro2783

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.

acronce avatar Jan 06 '23 03:01 acronce

Not yet sorry. I'll try to get to it soon.

jarro2783 avatar Jan 07 '23 09:01 jarro2783

Can you try the above commit to check if it is fixed?

jarro2783 avatar Jan 11 '23 10:01 jarro2783

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.

Screenshot 2023-01-15 at 5 33 34 PM

The branch that I checked out was "fix_iter_access" (commit 65b4e91f). Hopefully that's the correct branch.

acronce avatar Jan 16 '23 01:01 acronce

That's the right branch. I'll have another look at that.

jarro2783 avatar Jan 16 '23 05:01 jarro2783

I've pushed a fix for the example, and tried to fix the problem from the tests. Can you try both again?

jarro2783 avatar Jan 18 '23 20:01 jarro2783