Skip to content

Commit

Permalink
Fix unused parameters (#19)
Browse files Browse the repository at this point in the history
- removed parameter names for known types
- commented parameter names for string types
- moved virtual method body from header to implementation file
- moved cmakesettings to template
- added more options to pedantic builds
  • Loading branch information
mmahnic authored Aug 31, 2023
2 parents 94f6d59 + f0c552c commit 0d9e50d
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ build-*/
out/
xdata/

CMakeSettings.json

*.swp
*.*~
~*.*
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion example/basic_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int main( int argc, char** argv )
params.add_parameter( operation, "--sum", "-s" )
.nargs( 0 )
.absent( std::make_pair( max, INT_MIN ) )
.action( [&]( auto& target, const std::string& value ) {
.action( [&]( auto& target, const std::string& /*value*/ ) {
target = std::make_pair( sum, 0 );
} )
.help( "Sum the integers (default: find the max)" );
Expand Down
6 changes: 3 additions & 3 deletions example/basic_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CmdAccumulatorOptions : public argumentum::CommandOptions
public:
using CommandOptions::CommandOptions;

void execute( const ParseResult& res ) override
void execute( const ParseResult& ) override
{
const auto& numbers = common->numbers;
auto acc = accumulate( numbers.begin(), numbers.end(), operation.second, operation.first );
Expand All @@ -54,7 +54,7 @@ class CmdAccumulatorOptions : public argumentum::CommandOptions
params.add_parameter( operation, "--sum", "-s" )
.nargs( 0 )
.absent( std::make_pair( max, INT_MIN ) )
.action( [&]( auto& target, const std::string& value ) {
.action( [&]( auto& target, const std::string& /*value*/ ) {
target = std::make_pair( sum, 0 );
} )
.help( "Sum the integers (default: find the max)" );
Expand All @@ -76,7 +76,7 @@ class CmdEchoOptions : public argumentum::CommandOptions
params.add_parameters( common );
};

void execute( const ParseResult& res ) override
void execute( const ParseResult& ) override
{
for ( auto n : common->numbers )
cout << n << " ";
Expand Down
2 changes: 1 addition & 1 deletion example/basic_struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AccumulatorOptions : public argumentum::Options
params.add_parameter( operation, "--sum", "-s" )
.nargs( 0 )
.absent( std::make_pair( max, INT_MIN ) )
.action( [&]( auto& target, const std::string& value ) {
.action( [&]( auto& target, const std::string& /*value*/ ) {
target = std::make_pair( sum, 0 );
} )
.help( "Sum the integers (default: find the max)" );
Expand Down
8 changes: 4 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ if ( ARGUMENTUM_BUILD_STATIC_LIBS )
if( ARGUMENTUM_PEDANTIC )
target_compile_options( ${static_library_name}
PRIVATE
$<$<CXX_COMPILER_ID:GNU>:-Werror -Wall>
$<$<CXX_COMPILER_ID:MSVC>:/WX /permissive- /Za>
$<$<CXX_COMPILER_ID:GNU>:-Wall -Wextra -pedantic -Werror -Wl,--fatal-warnings>
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX /permissive- /Za>
)
endif()

Expand All @@ -46,8 +46,8 @@ if( ARGUMENTUM_IS_TOP_LEVEL )
if( ARGUMENTUM_PEDANTIC )
target_compile_options( ${internal_library_name}
PRIVATE
$<$<CXX_COMPILER_ID:GNU>:-Werror -Wall>
$<$<CXX_COMPILER_ID:MSVC>:/WX /permissive- /Za>
$<$<CXX_COMPILER_ID:GNU>:-Wall -Wextra -pedantic -Werror -Wl,--fatal-warnings>
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX /permissive- /Za>
)
endif()
endif()
2 changes: 1 addition & 1 deletion src/argumentstream_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace argumentum {

ARGUMENTUM_INLINE void ArgumentStream::peek( std::function<EPeekResult( std::string_view )> fnPeek )
ARGUMENTUM_INLINE void ArgumentStream::peek( std::function<EPeekResult( std::string_view )> )
{}

ARGUMENTUM_INLINE StdStreamArgumentStream::StdStreamArgumentStream(
Expand Down
5 changes: 1 addition & 4 deletions src/optionpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ class Options
{
public:
virtual ~Options() = default;
virtual void add_parameters( ParameterConfig& args )
{
// TODO (mmahnic): make method add_parameters( ParameterConfig) abstract.
}
virtual void add_parameters( ParameterConfig& args );

#ifdef ARGUMENTUM_DEPRECATED_ATTR
// Attributes are not handled well by clang-format so we use a macro.
Expand Down
5 changes: 4 additions & 1 deletion src/optionpack_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

namespace argumentum {

void Options::add_parameters( ParameterConfig& )
{}

void Options::add_arguments( argument_parser& parser )
{
auto params = parser.params();
Expand All @@ -24,7 +27,7 @@ ARGUMENTUM_INLINE const std::string& CommandOptions::getName() const
return mName;
}

ARGUMENTUM_INLINE void CommandOptions::execute( const ParseResult& result )
ARGUMENTUM_INLINE void CommandOptions::execute( const ParseResult& )
{}

} // namespace argumentum
2 changes: 1 addition & 1 deletion src/parserconfig_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ ARGUMENTUM_INLINE std::ostream* ParserConfig::Data::output_stream() const
}

ARGUMENTUM_INLINE std::shared_ptr<IFormatHelp> ParserConfig::Data::help_formatter(
const std::string& helpOption ) const
const std::string& /*helpOption*/ ) const
{
return mpHelpFormatter ? mpHelpFormatter : std::make_shared<HelpFormatter>();
}
Expand Down
6 changes: 3 additions & 3 deletions src/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class ConvertedValue : public Value
}

template<typename TVar>
void assignMissing( std::optional<std::vector<TVar>>& var, const std::string& value )
void assignMissing( std::optional<std::vector<TVar>>& var, const std::string& /*value*/ )
{
if ( !var.has_value() )
var = std::vector<TVar>{};
Expand All @@ -228,7 +228,7 @@ class ConvertedValue : public Value
}

template<typename TVar>
void assignMissing( std::optional<TVar>& var, const std::string& value )
void assignMissing( std::optional<TVar>& var, const std::string& /*value*/ )
{
if ( !var.has_value() )
var = TVar{};
Expand All @@ -249,7 +249,7 @@ class ConvertedValue : public Value

template<typename TVar,
std::enable_if_t<!has_from_string<TVar>::value && !can_convert<TVar>::value, int> = 0>
void assign( TVar& var, const std::string& value )
void assign( TVar&, const std::string& value )
{
Notifier::warn( "Assignment is not implemented. ('" + value + "')" );
}
Expand Down
8 changes: 8 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ add_executable( argumentumTests
value_t.cpp
)

if( ARGUMENTUM_PEDANTIC )
target_compile_options( argumentumTests
PRIVATE
$<$<CXX_COMPILER_ID:GNU>:-Wall -Wextra -pedantic -Werror -Wl,--fatal-warnings>
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX /permissive- /Za>
)
endif()

target_link_libraries( argumentumTests
${GTEST_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
Expand Down
2 changes: 1 addition & 1 deletion test/action_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ TEST( ArgumentParserActionTest, shouldReadOptionNameFromActionEvnironment )

TEST( ArgumentParserActionTest, shouldReportErrorsThroughActionEvnironment )
{
auto actionEnv = []( std::string& target, const std::string& value, Environment& env ) {
auto actionEnv = []( std::string& /*target*/, const std::string& /*value*/, Environment& env ) {
env.add_error( "Something is wrong" );
};

Expand Down

0 comments on commit 0d9e50d

Please sign in to comment.