Skip to content

Commit

Permalink
Merge pull request #204 from p-ranav/bugfix/warnings
Browse files Browse the repository at this point in the history
Added -Wshadow and -Wconversion to CXX_FLAGS and fixed warnings (related to #159)
  • Loading branch information
p-ranav authored Sep 21, 2022
2 parents 1ebaccc + 616062e commit 2335da9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions include/argparse/argparse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,9 @@ class Argument {
return get<T>() == rhs;
} else {
auto lhs = get<T>();
return std::equal(
std::begin(lhs), std::end(lhs), std::begin(rhs), std::end(rhs),
[](const auto &lhs, const auto &rhs) { return lhs == rhs; });
return std::equal(std::begin(lhs), std::end(lhs), std::begin(rhs),
std::end(rhs),
[](const auto &a, const auto &b) { return a == b; });
}
}

Expand Down Expand Up @@ -730,10 +730,10 @@ class Argument {
};

// precondition: we have consumed or will consume at least one digit
auto consume_digits = [=](std::string_view s) {
auto consume_digits = [=](std::string_view sd) {
// NOLINTNEXTLINE(readability-qualified-auto)
auto it = std::find_if_not(std::begin(s), std::end(s), is_digit);
return s.substr(static_cast<std::size_t>(it - std::begin(s)));
auto it = std::find_if_not(std::begin(sd), std::end(sd), is_digit);
return sd.substr(static_cast<std::size_t>(it - std::begin(sd)));
};

switch (lookahead(s)) {
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if(MSVC)
endif()
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
# Update if necessary
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -pedantic -Wsign-conversion")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -pedantic -Wsign-conversion -Wshadow -Wconversion")
endif()

if(NOT CMAKE_BUILD_TYPE)
Expand Down
14 changes: 7 additions & 7 deletions test/test_parse_args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ TEST_CASE("Parse a vector of string arguments and construct objects" *

class Foo {
public:
Foo(const std::string &value) : value(value) {}
std::string value;
Foo(const std::string &value) : m_value(value) {}
std::string m_value;
};

argparse::ArgumentParser program("test");
Expand All @@ -211,9 +211,9 @@ TEST_CASE("Parse a vector of string arguments and construct objects" *
program.parse_args({"test", "--vector", "abc", "def", "ghi", "jkl", "mno"});
auto vector = program.get<std::vector<Foo>>("--vector");
REQUIRE(vector.size() == 5);
REQUIRE(vector[0].value == Foo("abc").value);
REQUIRE(vector[1].value == Foo("def").value);
REQUIRE(vector[2].value == Foo("ghi").value);
REQUIRE(vector[3].value == Foo("jkl").value);
REQUIRE(vector[4].value == Foo("mno").value);
REQUIRE(vector[0].m_value == Foo("abc").m_value);
REQUIRE(vector[1].m_value == Foo("def").m_value);
REQUIRE(vector[2].m_value == Foo("ghi").m_value);
REQUIRE(vector[3].m_value == Foo("jkl").m_value);
REQUIRE(vector[4].m_value == Foo("mno").m_value);
}
2 changes: 1 addition & 1 deletion test/test_repr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ TEST_CASE_TEMPLATE("Test built-in float types representation" *
test_suite("repr"),
T, float, double, long double) {
std::stringstream ss;
T v = 0.3333333333;
T v = static_cast<T>(0.3333333333);
ss << v;
REQUIRE(argparse::details::repr(v) == ss.str());
}
Expand Down

0 comments on commit 2335da9

Please sign in to comment.