From 616062e2bfa00ce1e5c747593cfc3ce74702b124 Mon Sep 17 00:00:00 2001 From: Pranav Srinivas Kumar Date: Wed, 21 Sep 2022 07:43:46 -0700 Subject: [PATCH] Added -Wshadow and -Wconversion to CXX_FLAGS and fixed warnings --- include/argparse/argparse.hpp | 12 ++++++------ test/CMakeLists.txt | 2 +- test/test_parse_args.cpp | 14 +++++++------- test/test_repr.cpp | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/include/argparse/argparse.hpp b/include/argparse/argparse.hpp index 8235ba80..c0e13dd1 100644 --- a/include/argparse/argparse.hpp +++ b/include/argparse/argparse.hpp @@ -610,9 +610,9 @@ class Argument { return get() == rhs; } else { auto lhs = get(); - 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; }); } } @@ -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(it - std::begin(s))); + auto it = std::find_if_not(std::begin(sd), std::end(sd), is_digit); + return sd.substr(static_cast(it - std::begin(sd))); }; switch (lookahead(s)) { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index dd7aecc0..b61040fe 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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) diff --git a/test/test_parse_args.cpp b/test/test_parse_args.cpp index 76e7f0ee..7a38abf2 100644 --- a/test/test_parse_args.cpp +++ b/test/test_parse_args.cpp @@ -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"); @@ -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>("--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); } diff --git a/test/test_repr.cpp b/test/test_repr.cpp index dc7d1c7e..c09c3ac5 100644 --- a/test/test_repr.cpp +++ b/test/test_repr.cpp @@ -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(0.3333333333); ss << v; REQUIRE(argparse::details::repr(v) == ss.str()); }