GNOME Bugzilla – Bug 393571
option parser ignores default values
Last modified: 2007-02-10 19:15:42 UTC
The contents of the option value passed to Glib::OptionGroup::add_entry() by reference are always cleared. E.g. if you do this: bool do_foo = true; Glib::OptionEntry entry; Glib::OptionGroup group; entry.set_long_description("no-foo"); entry.set_flags(Glib::OptionEntry::FLAG_REVERSE); group.add_entry(entry, do_foo); ... After parsing the options, do_foo will always be false, irrespective of whether you pass the "--no-foo" option or not. Looking at the code, it appears that OptionGroup::CppOptionEntry::allocate_c_arg() just always initializes the allocated value using the default constructor, instead of copying the value from the location passed to OptionGroup::add_entry().
Do you mean that if we do, for instance: Glib::ustring arg_foo = "some default value"; Glib::OptionEntry entry1; entry1.set_long_name("foo"); entry1.set_short_name('f'); entry1.set_description("The Foo"); add_entry(entry1, arg_foo); Then arg_foo will be "" if the user does not specify it? So the caller has to check whether it's empty and then explicitly use a default value. Yes, I had not considered that would be wanted. I guess I just like to initialize output variables in case the caller doesn't do it. That might be a disadvantage here.
I already stumbled about this some time ago, however it seems that the patch got lost somehow. Refer to http://bugzilla.gnome.org/show_bug.cgi?id=336598.
*** This bug has been marked as a duplicate of 336598 ***