mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-03 22:54:39 +00:00
Merge pull request #204 from p-ranav/bugfix/warnings
Added -Wshadow and -Wconversion to CXX_FLAGS and fixed warnings (related to #159)
This commit is contained in:
commit
2335da9478
@ -610,9 +610,9 @@ public:
|
|||||||
return get<T>() == rhs;
|
return get<T>() == rhs;
|
||||||
} else {
|
} else {
|
||||||
auto lhs = get<T>();
|
auto lhs = get<T>();
|
||||||
return std::equal(
|
return std::equal(std::begin(lhs), std::end(lhs), std::begin(rhs),
|
||||||
std::begin(lhs), std::end(lhs), std::begin(rhs), std::end(rhs),
|
std::end(rhs),
|
||||||
[](const auto &lhs, const auto &rhs) { return lhs == rhs; });
|
[](const auto &a, const auto &b) { return a == b; });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -730,10 +730,10 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// precondition: we have consumed or will consume at least one digit
|
// 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)
|
// NOLINTNEXTLINE(readability-qualified-auto)
|
||||||
auto it = std::find_if_not(std::begin(s), std::end(s), is_digit);
|
auto it = std::find_if_not(std::begin(sd), std::end(sd), is_digit);
|
||||||
return s.substr(static_cast<std::size_t>(it - std::begin(s)));
|
return sd.substr(static_cast<std::size_t>(it - std::begin(sd)));
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (lookahead(s)) {
|
switch (lookahead(s)) {
|
||||||
|
@ -10,7 +10,7 @@ if(MSVC)
|
|||||||
endif()
|
endif()
|
||||||
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
|
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
|
||||||
# Update if necessary
|
# 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()
|
endif()
|
||||||
|
|
||||||
if(NOT CMAKE_BUILD_TYPE)
|
if(NOT CMAKE_BUILD_TYPE)
|
||||||
|
@ -200,8 +200,8 @@ TEST_CASE("Parse a vector of string arguments and construct objects" *
|
|||||||
|
|
||||||
class Foo {
|
class Foo {
|
||||||
public:
|
public:
|
||||||
Foo(const std::string &value) : value(value) {}
|
Foo(const std::string &value) : m_value(value) {}
|
||||||
std::string value;
|
std::string m_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
@ -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"});
|
program.parse_args({"test", "--vector", "abc", "def", "ghi", "jkl", "mno"});
|
||||||
auto vector = program.get<std::vector<Foo>>("--vector");
|
auto vector = program.get<std::vector<Foo>>("--vector");
|
||||||
REQUIRE(vector.size() == 5);
|
REQUIRE(vector.size() == 5);
|
||||||
REQUIRE(vector[0].value == Foo("abc").value);
|
REQUIRE(vector[0].m_value == Foo("abc").m_value);
|
||||||
REQUIRE(vector[1].value == Foo("def").value);
|
REQUIRE(vector[1].m_value == Foo("def").m_value);
|
||||||
REQUIRE(vector[2].value == Foo("ghi").value);
|
REQUIRE(vector[2].m_value == Foo("ghi").m_value);
|
||||||
REQUIRE(vector[3].value == Foo("jkl").value);
|
REQUIRE(vector[3].m_value == Foo("jkl").m_value);
|
||||||
REQUIRE(vector[4].value == Foo("mno").value);
|
REQUIRE(vector[4].m_value == Foo("mno").m_value);
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ TEST_CASE_TEMPLATE("Test built-in float types representation" *
|
|||||||
test_suite("repr"),
|
test_suite("repr"),
|
||||||
T, float, double, long double) {
|
T, float, double, long double) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
T v = 0.3333333333;
|
T v = static_cast<T>(0.3333333333);
|
||||||
ss << v;
|
ss << v;
|
||||||
REQUIRE(argparse::details::repr(v) == ss.str());
|
REQUIRE(argparse::details::repr(v) == ss.str());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user