Skip to content

std::getopts::opts_present() is broken #4705

@illuloid

Description

@illuloid

It appears that opts_present() as it is now is broken. It calls find_opt() for each option string and returns true as soon as result is matched against Some(_), but find_opt() returns Some(i) (i being the index of the opt in the Matches.opts vector) when an option is legit (regardless of it being matched). This leads to opts_present() returning true always unless one of the options in the input vector is absent from Matches.opts. Test suite works because it is tested true against options that have been specified, and false against illegal options, but there is no test for optional arguments that have not been specified in the command line. Calling opt_present() instead of opts_present() for each string in vector works as expected.

TL;DR: opts_present() behaves as if it were named opts_matchable().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions