From 6c4bddb990a7a2f92b07b00c4ff545064d8c2775 Mon Sep 17 00:00:00 2001 From: Christoph Hindermann <10599299+BitMaskMixer@users.noreply.github.com> Date: Fri, 20 Oct 2023 19:52:24 +0200 Subject: [PATCH] CMakefile: Use -Wpedantic, -Werror and -Wextra for compilation in gcc. Fixed warnings --- CMakeLists.txt | 2 +- include/argparse/argparse.hpp | 4 ++-- test/CMakeLists.txt | 2 +- test/test_help.cpp | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 19d89420..91463f80 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ project(argparse ) option(ARGPARSE_INSTALL "Include an install target" ON) -option(ARGPARSE_BUILD_TESTS "Build tests" OFF) +option(ARGPARSE_BUILD_TESTS "Build tests" ON) include(GNUInstallDirs) include(CMakePackageConfigHelpers) diff --git a/include/argparse/argparse.hpp b/include/argparse/argparse.hpp index b877e6fd..588666cb 100644 --- a/include/argparse/argparse.hpp +++ b/include/argparse/argparse.hpp @@ -680,8 +680,8 @@ class Argument { // align multiline help message auto stream_width = stream.width(); auto name_padding = std::string(name_stream.str().size(), ' '); - auto pos = 0; - auto prev = 0; + auto pos = std::string::size_type{}; + auto prev = std::string::size_type{}; auto first_line = true; auto hspace = " "; // minimal space between name and help message stream << name_stream.str(); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a903f09f..2be4acc4 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 -Wshadow -Wconversion") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -Wpedantic -Wsign-conversion -Wshadow -Wconversion -Werror -Wextra") endif() if(NOT CMAKE_BUILD_TYPE) diff --git a/test/test_help.cpp b/test/test_help.cpp index 2f29e560..ec5b6bd7 100644 --- a/test/test_help.cpp +++ b/test/test_help.cpp @@ -104,7 +104,7 @@ R"(#Lorem ipsum dolor sit amet, consectetur adipiscing elit. stream << program; std::istringstream iss(stream.str()); - int help_message_start = -1; + auto help_message_start = std::string::npos; std::string line; while (std::getline(iss, line)) { // Find the position of '#', which indicates the start of the help message line @@ -114,7 +114,7 @@ R"(#Lorem ipsum dolor sit amet, consectetur adipiscing elit. continue; } - if (help_message_start == -1) { + if (help_message_start == std::string::npos) { help_message_start = pos; } else { REQUIRE(pos == help_message_start);