GNOME Bugzilla – Bug 336598
Glib option parser: Default arguments are overwritten
Last modified: 2007-02-10 19:26:29 UTC
Please describe the problem: When giving an argument to Glib::OptionGroup::add_entry, glibmm resets it to zero in Glib::OptionContext::parse if the argument was not given on the command line. This makes it unpossible to have non-zero default arguments. The problem does not occur using the plain C API of GOption. Steps to reproduce: 1. Compile the attached gopt.c. 2. Compile the attached goptmm.cc. 3. Run both without any command line arguments. 4. Compare the results. Actual results: The C++ overrides the default arguments, the C version does not. Expected results: Both versions produce the same result. Does this happen every time? Yes. Other information:
Created attachment 62373 [details] C version with working default arguments
Created attachment 62374 [details] C++ version overriding default arguments
Created attachment 62376 [details] [review] Proposed patch
Excellent. I have committed that, with some small changes: - Some temporary variables to that the code is a little bit more explicit, just to suite my taste. - Swapped the string/filename parts because filenames should be std::string. - Used a default value in examples/options/ I also took the hint and used static_cast<> for the other casts in this file. Well done and thanks.
Reopened because this doesn't actually seem to have been applied.
*** Bug 393571 has been marked as a duplicate of this bug. ***
I have restored the changes to the glibmm-2-8, glibmm-2-10 and glibmm-2-12 branches. They had survived in trunk (future glibmm 2.13/2.14). It was my fault.