(Go: >> BACK << -|- >> HOME <<)

Skip to content

Commit

Permalink
fix compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Laning committed May 30, 2020
1 parent b758a9a commit 5c60d66
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 37 deletions.
38 changes: 29 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,35 @@ set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
option(ARGPARSE_TEST_ENABLE "Build unit tests" ON)
option(ARGPARSE_BUILD_EXAMPLE "Build example" ON)
if(UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -pedantic-errors -Wall -Wextra \
-Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 \
-Winit-self -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wnoexcept \
-Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow \
-Wsign-conversion -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 \
-Wswitch-default -Wundef -Werror -Wno-unused -Winline -Wconversion -Wfloat-equal\
-Weffc++")
endif(UNIX)
if(WIN32)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /Wall /WX -Wno-c++98-compat -Wno-c++98-compat-pedantic \
-Wno-gnu-zero-variadic-macro-arguments"
)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /Wall /WX")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(
CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -pedantic-errors -Wall -Wextra \
-Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 \
-Winit-self -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wnoexcept \
-Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow \
-Wsign-conversion -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 \
-Wswitch-default -Wundef -Werror -Wno-unused -Winline -Wconversion -Wfloat-equal\
-Weffc++"
)
endif()
elseif(UNIX)
set(
CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -pedantic-errors -Wall -Wextra \
-Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 \
-Winit-self -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wnoexcept \
-Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow \
-Wsign-conversion -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 \
-Wswitch-default -Wundef -Werror -Wno-unused -Winline -Wconversion -Wfloat-equal\
-Weffc++"
)
endif()

enable_testing()

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ int main(int argc, const char* argv[]) {
case 2:
std::cout << "an even more verbose string" << std::endl;
// fall through
[[clang::fallthrough]];
case 1:
std::cout << "a verbose string" << std::endl;
// fall through
[[clang::fallthrough]];
default:
std::cout << "some verbosity" << std::endl;
}
Expand Down
4 changes: 2 additions & 2 deletions argparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ class ArgumentParser {
continue;
}
if (_help_enabled && (current_arg == "-h" || current_arg == "--help")) {
_arguments[_name_map["help"]]._found = true;
_arguments[static_cast<size_t>(_name_map["help"])]._found = true;
} else if (argv_index == argc - 1 &&
_positional_arguments.find(Argument::Position::LAST) !=
_positional_arguments.end()) {
Expand Down Expand Up @@ -395,7 +395,7 @@ class ArgumentParser {
return err;
}
for (auto &p : _positional_arguments) {
Argument &a = _arguments[p.second];
Argument &a = _arguments[static_cast<size_t>(p.second)];
if (a._values.size() > 0 && a._values[0][0] == '-') {
std::string name = detail::_ltrim_copy(a._values[0], [](int c) -> bool {
return c != static_cast<int>('-');
Expand Down
2 changes: 2 additions & 0 deletions example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ int main(int argc, const char* argv[]) {
case 2:
std::cout << "an even more verbose string" << std::endl;
// fall through
[[clang::fallthrough]];
case 1:
std::cout << "a verbose string" << std::endl;
// fall through
[[clang::fallthrough]];
default:
std::cout << "some verbosity" << std::endl;
}
Expand Down
53 changes: 27 additions & 26 deletions tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,34 +375,35 @@ TEST(
#define TT(name) \
{ #name, name }
using test = std::function<result()>;
std::unordered_map<std::string, test> tests{
TT(no_args),
TT(short_optional_flag_exists),
TT(short_optional_flag_does_not_exist),
TT(short_required_flag_exists),
TT(short_required_flag_does_not_exist),
TT(long_optional_flag_exists),
TT(long_short_optional_flag_pair_exists),
TT(short_combined_flags),
TT(vector_flag_empty),
TT(vector_flag),
TT(short_and_vector_flag),
TT(long_required_flag_exists),
TT(long_required_flag_does_not_exist),
TT(short_help_flag),
TT(long_help_flag),
TT(flag_values),
TT(arg_count),
TT(arg_count_more),
TT(arg_count_less),
TT(arg_count_zero),
TT(positional_argument_found),
TT(positional_argument_not_found),
TT(positional_argument_overrun),
TT(positional_argument_last),
TT(positional_argument_last_override)};

int main(int argc, const char* argv[]) {
std::unordered_map<std::string, test> tests{
TT(no_args),
TT(short_optional_flag_exists),
TT(short_optional_flag_does_not_exist),
TT(short_required_flag_exists),
TT(short_required_flag_does_not_exist),
TT(long_optional_flag_exists),
TT(long_short_optional_flag_pair_exists),
TT(short_combined_flags),
TT(vector_flag_empty),
TT(vector_flag),
TT(short_and_vector_flag),
TT(long_required_flag_exists),
TT(long_required_flag_does_not_exist),
TT(short_help_flag),
TT(long_help_flag),
TT(flag_values),
TT(arg_count),
TT(arg_count_more),
TT(arg_count_less),
TT(arg_count_zero),
TT(positional_argument_found),
TT(positional_argument_not_found),
TT(positional_argument_overrun),
TT(positional_argument_last),
TT(positional_argument_last_override)};

std::vector<result> results;
size_t passed = 0;
if (argc > 1) {
Expand Down

0 comments on commit 5c60d66

Please sign in to comment.