After upgrading g++ package to 12.1.0 on archlinux I see the following
compilation error:
/usr/include/argparse/argparse.hpp: In member function ‘void argparse::ArgumentParser::index_argument(list_iterator)’:
/usr/include/argparse/argparse.hpp:1167:34: error: ‘as_const’ is not a member of ‘std’; did you mean ‘is_const’?
1167 | for (const auto &name : std::as_const(it->m_names)) {
| ^~~~~~~~
| is_const
It turns out that std::as_const comes from <utility> header [1] which
was not explicitly included.
[1] https://en.cppreference.com/w/cpp/utility/as_const
As far as I can tell, this statement is never true.
When m_values.size() < *expected, ::consume has already thrown "Too few
arguments..." before ::validate is called.
When m_values.size() > *expected, ArgumentParser::parse_args_internal
has already thrown "Maximum number of positional arguments exceeded"
before ::validate is called.
If ::remaining is used to avoid the last exception, this Argument will
always consume the expected number of values, hence this expression is
again false.
Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
This regression was caused by commit
ea1f7ef663, which didn't add "\n" to the
version printing statement. We use std::endl now for compatibility
across platforms.
I am seeing too many errors due to bad tool configuration, not from
problems in project code. So, disable SA until I can make it work more
reliably.
Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
The 'unused' variable in both cases is most-definitely unused in the loop.
This is a cppcheck warning that appeared after moving these two loops to
range-for.
Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
This code was previously moved from ::parse_args to its own method, but
has since been simplified. Moving the actual work to Argument::validate
in commit 603e87ae6 leaves a single loop that fits back into ::parse_args.
Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
The new naming pattern is CamelCase for structs, except parse_number as a
primarily callable interface. Trait structs are named Has*Traits
and constexpr variables to the struct template are named Is*.
Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
Most changes are to better fit within "ColumnLimit: 80".
The change from "T &&... var" to "T &&...var" is caused by
"PointerAlignment: Right".
Member functions chained from add_argument() use ContinuationIndentWidth,
which is set to 4. Setting ContinuationIndentWidth to 2 causes many
other continuation lines to change. So, this commit uses the original
value (i.e. 4) as the preferred size.
Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
The "Cpp11" alias is deprecated for Latest (a rolling standard). For now,
stick to C++17.
Includes end-of-line whitespace removal.
Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
Also converts most C-style arrays to a std::array onjects. The check is
disabled for ArgumentParser::parse_args(int, const char *const[]) as this
is a helper function to convert away from a common input format.
Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
The two functions previously flagged by this check,
Argument::is_decimal_literal and Argument::validate, fell below the
default Cognitive Complexity threshold as a result of the branch
simplification for the readability-else-after-return check.
Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
A common pattern in the previous code was goto/return/throw if a condition
is true, else goto/return/throw something different. The new pattern
uses the fact that the second goto/return/throw is only reachable when the
first goto/return/throw is not called.
Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
Following the clang-tidy suggested fix in consume_digits causes compile
failures with MSVC 19.29 in our CI.
Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
Adds names recommended by clang-tidy (e.g. "unused").
Note that clang-tidy v12 appears to detect unnamed parameters in lambdas,
while clang-tidy v13 does not.
Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
Enabling this check caught the implicit bool conversion with
default_arguments::operator& fixed in the previous commit.
Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
operator& should return combined values of the same type, not a new type
(i.e. bool). This is much more verbose, but easier to reason about
without implied conversion.
Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
Upstream StaticAnalysis looks to be changing for more flexibility with
source files to process. While these changes may eventually benefit
argparse, the public interfaces are in flux and we need a stable tool.
argparse also needs a SA change which is not yet upstream.
Trying to run clang-tidy via StaticAnalysis on a single file in a
directory with many source file is not easy, so move the analysis kernel
to a location (i.e. tools) where it is the only C++ source file.
Another benefit is cppcheck no longer needs to be told to ignore the test
sources.
Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>