Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/argparse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1897,7 +1897,7 @@
m_options.mutually_exclusive_group = group;
}

~ArgumentBuilder() noexcept(false)

Check failure on line 1900 in include/argparse.hpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Ensure that destructor of "ArgumentBuilder" is exception-free and declare it "noexcept"

See more on https://sonarcloud.io/project/issues?id=kkarbowiak_cpp-argparse&issues=AZrlhyLBj3x7_pzjz-5I&open=AZrlhyLBj3x7_pzjz-5I&pullRequest=189
{
if ((m_options.action == argparse::version) && m_options.help.empty())
{
Expand All @@ -1909,16 +1909,22 @@
if (m_options.mutually_exclusive_group != nullptr
&& (!m_options.nargs.has_value()
|| (!std::holds_alternative<Nargs>(*m_options.nargs)
|| (std::get<Nargs>(*m_options.nargs) != zero_or_one

Check failure on line 1912 in include/argparse.hpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do not throw uncaught exceptions in a destructor.

See more on https://sonarcloud.io/project/issues?id=kkarbowiak_cpp-argparse&issues=AZrlhyLBj3x7_pzjz-5J&open=AZrlhyLBj3x7_pzjz-5J&pullRequest=189
&& std::get<Nargs>(*m_options.nargs) != zero_or_more))))

Check failure on line 1913 in include/argparse.hpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do not throw uncaught exceptions in a destructor.

See more on https://sonarcloud.io/project/issues?id=kkarbowiak_cpp-argparse&issues=AZrlhyLBj3x7_pzjz-5K&open=AZrlhyLBj3x7_pzjz-5K&pullRequest=189
{
throw option_error("mutually exclusive arguments must be optional");

Check failure on line 1915 in include/argparse.hpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do not throw uncaught exceptions in a destructor.

See more on https://sonarcloud.io/project/issues?id=kkarbowiak_cpp-argparse&issues=AZrlhyLBj3x7_pzjz-5L&open=AZrlhyLBj3x7_pzjz-5L&pullRequest=189
}

m_arguments.emplace_back(PositionalArgument(std::move(m_options)));
}
else
{
if (m_options.mutually_exclusive_group != nullptr
&& m_options.required)
{
throw option_error("mutually exclusive arguments must be optional");

Check failure on line 1925 in include/argparse.hpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do not throw uncaught exceptions in a destructor.

See more on https://sonarcloud.io/project/issues?id=kkarbowiak_cpp-argparse&issues=AZrlhyLBj3x7_pzjz-5M&open=AZrlhyLBj3x7_pzjz-5M&pullRequest=189
}

m_arguments.emplace_back(OptionalArgument(std::move(m_options)));
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/unittest/test_argument_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,14 @@ TEST_CASE("Adding an optional argument to a mutually exclusive group does not re
CHECK_NOTHROW(group.add_argument("-o"));
}

TEST_CASE("Adding a required optional argument to a mutually exclusive group results in error")
{
auto parser = argparse::ArgumentParser();
auto group = parser.add_mutually_exclusive_group();

CHECK_THROWS_WITH_AS(group.add_argument("-o").required(true), "mutually exclusive arguments must be optional", argparse::option_error);
}

TEST_CASE("Test combining Handle values")
{
CHECK((argparse::Handle::none | argparse::Handle::errors) == argparse::Handle::errors);
Expand Down