Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCC warns about unused parameters in ArgumentParser class #167

Closed
ericonr opened this issue Apr 13, 2022 · 3 comments · Fixed by #170
Closed

GCC warns about unused parameters in ArgumentParser class #167

ericonr opened this issue Apr 13, 2022 · 3 comments · Fixed by #170

Comments

@ericonr
Copy link
Contributor

ericonr commented Apr 13, 2022

Seems to be caused by b5fb663

[1/2] Compiling C++ object decode-reg.p/decode-reg.cc.o
In file included from ../decode-reg.cc:16:
../subprojects/argparse-2.3/include/argparse/argparse.hpp: In instantiation of ‘argparse::ArgumentParser::ArgumentParser(std::string, std::string, argparse::default_arguments)::<lambda(const auto:33&)> [with auto:33 = std::__cxx11::basic_string<char>]’:
/usr/include/c++/9/type_traits:2330:26:   required by substitution of ‘template<class _Fn, class ... _Args> static std::__result_of_success<decltype (declval<_Fn>()((declval<_Args>)()...)), std::__invoke_other> std::__result_of_other_impl::_S_test(int) [with _Fn = argparse::ArgumentParser::ArgumentParser(std::string, std::string, argparse::default_arguments)::<lambda(const auto:33&)>; _Args = {const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >}]’
/usr/include/c++/9/type_traits:2341:55:   required from ‘struct std::__result_of_impl<false, false, argparse::ArgumentParser::ArgumentParser(std::string, std::string, argparse::default_arguments)::<lambda(const auto:33&)>, const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >’
/usr/include/c++/9/type_traits:2781:12:   recursively required by substitution of ‘template<class _Result, class _Ret> struct std::__is_invocable_impl<_Result, _Ret, true, std::__void_t<typename _Result::type> > [with _Result = std::__invoke_result<argparse::ArgumentParser::ArgumentParser(std::string, std::string, argparse::default_arguments)::<lambda(const auto:33&)>, const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >; _Ret = void]’
/usr/include/c++/9/type_traits:2781:12:   required from ‘struct std::is_invocable<argparse::ArgumentParser::ArgumentParser(std::string, std::string, argparse::default_arguments)::<lambda(const auto:33&)>, const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >’
/usr/include/c++/9/type_traits:2818:27:   required from ‘constexpr const bool std::is_invocable_v<argparse::ArgumentParser::ArgumentParser(std::string, std::string, argparse::default_arguments)::<lambda(const auto:33&)>, const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >’
../subprojects/argparse-2.3/include/argparse/argparse.hpp:391:32:   required by substitution of ‘template<class F, class ... Args> std::enable_if_t<is_invocable_v<F, Args ..., const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, argparse::Argument&> argparse::Argument::action(F&&, Args&& ...) [with F = argparse::ArgumentParser::ArgumentParser(std::string, std::string, argparse::default_arguments)::<lambda(const auto:33&)>; Args = {}]’
../subprojects/argparse-2.3/include/argparse/argparse.hpp:861:12:   required from here
../subprojects/argparse-2.3/include/argparse/argparse.hpp:858:35: warning: unused parameter ‘unused’ [-Wunused-parameter]
  858 |           .action([&](const auto &unused) {
      |                       ~~~~~~~~~~~~^~~~~~
../subprojects/argparse-2.3/include/argparse/argparse.hpp: In instantiation of ‘argparse::ArgumentParser::ArgumentParser(std::string, std::string, argparse::default_arguments)::<lambda(const auto:34&)> [with auto:34 = std::__cxx11::basic_string<char>]’:
/usr/include/c++/9/type_traits:2330:26:   required by substitution of ‘template<class _Fn, class ... _Args> static std::__result_of_success<decltype (declval<_Fn>()((declval<_Args>)()...)), std::__invoke_other> std::__result_of_other_impl::_S_test(int) [with _Fn = argparse::ArgumentParser::ArgumentParser(std::string, std::string, argparse::default_arguments)::<lambda(const auto:34&)>; _Args = {const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >}]’
/usr/include/c++/9/type_traits:2341:55:   required from ‘struct std::__result_of_impl<false, false, argparse::ArgumentParser::ArgumentParser(std::string, std::string, argparse::default_arguments)::<lambda(const auto:34&)>, const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >’
/usr/include/c++/9/type_traits:2781:12:   recursively required by substitution of ‘template<class _Result, class _Ret> struct std::__is_invocable_impl<_Result, _Ret, true, std::__void_t<typename _Result::type> > [with _Result = std::__invoke_result<argparse::ArgumentParser::ArgumentParser(std::string, std::string, argparse::default_arguments)::<lambda(const auto:34&)>, const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >; _Ret = void]’
/usr/include/c++/9/type_traits:2781:12:   required from ‘struct std::is_invocable<argparse::ArgumentParser::ArgumentParser(std::string, std::string, argparse::default_arguments)::<lambda(const auto:34&)>, const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >’
/usr/include/c++/9/type_traits:2818:27:   required from ‘constexpr const bool std::is_invocable_v<argparse::ArgumentParser::ArgumentParser(std::string, std::string, argparse::default_arguments)::<lambda(const auto:34&)>, const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >’
../subprojects/argparse-2.3/include/argparse/argparse.hpp:391:32:   required by substitution of ‘template<class F, class ... Args> std::enable_if_t<is_invocable_v<F, Args ..., const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, argparse::Argument&> argparse::Argument::action(F&&, Args&& ...) [with F = argparse::ArgumentParser::ArgumentParser(std::string, std::string, argparse::default_arguments)::<lambda(const auto:34&)>; Args = {}]’
../subprojects/argparse-2.3/include/argparse/argparse.hpp:872:12:   required from here
../subprojects/argparse-2.3/include/argparse/argparse.hpp:869:35: warning: unused parameter ‘unused’ [-Wunused-parameter]
  869 |           .action([&](const auto &unused) {
      |                       ~~~~~~~~~~~~^~~~~~
../subprojects/argparse-2.3/include/argparse/argparse.hpp: In instantiation of ‘argparse::Argument::Argument(std::array<std::basic_string_view<char>, N>&&, std::index_sequence<__indices ...>) [with long unsigned int N = 2; long unsigned int ...I = {0, 1}; std::index_sequence<__indices ...> = std::integer_sequence<long unsigned int, 0, 1>]’:
../subprojects/argparse-2.3/include/argparse/argparse.hpp:365:61:   required from ‘argparse::Argument::Argument(std::array<std::basic_string_view<char>, N>&&) [with long unsigned int N = 2]’
/usr/include/c++/9/ext/new_allocator.h:146:4:   required from ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = argparse::Argument; _Args = {std::array<std::basic_string_view<char, std::char_traits<char> >, 2>}; _Tp = std::_List_node<argparse::Argument>]’
/usr/include/c++/9/bits/alloc_traits.h:483:4:   required from ‘static void std::allocator_traits<std::allocator<_Tp1> >::construct(std::allocator_traits<std::allocator<_Tp1> >::allocator_type&, _Up*, _Args&& ...) [with _Up = argparse::Argument; _Args = {std::array<std::basic_string_view<char, std::char_traits<char> >, 2>}; _Tp = std::_List_node<argparse::Argument>; std::allocator_traits<std::allocator<_Tp1> >::allocator_type = std::allocator<std::_List_node<argparse::Argument> >]’
/usr/include/c++/9/bits/stl_list.h:633:33:   required from ‘std::__cxx11::list<_Tp, _Alloc>::_Node* std::__cxx11::list<_Tp, _Alloc>::_M_create_node(_Args&& ...) [with _Args = {std::array<std::basic_string_view<char, std::char_traits<char> >, 2>}; _Tp = argparse::Argument; _Alloc = std::allocator<argparse::Argument>; std::__cxx11::list<_Tp, _Alloc>::_Node = std::_List_node<argparse::Argument>]’
/usr/include/c++/9/bits/list.tcc:92:9:   required from ‘std::__cxx11::list<_Tp, _Alloc>::iterator std::__cxx11::list<_Tp, _Alloc>::emplace(std::__cxx11::list<_Tp, _Alloc>::const_iterator, _Args&& ...) [with _Args = {std::array<std::basic_string_view<char, std::char_traits<char> >, 2>}; _Tp = argparse::Argument; _Alloc = std::allocator<argparse::Argument>; std::__cxx11::list<_Tp, _Alloc>::iterator = std::_List_iterator<argparse::Argument>; std::__cxx11::list<_Tp, _Alloc>::const_iterator = std::_List_const_iterator<argparse::Argument>]’
../subprojects/argparse-2.3/include/argparse/argparse.hpp:913:10:   required from ‘argparse::Argument& argparse::ArgumentParser::add_argument(Targs ...) [with Targs = {const char*, const char*}]’
../subprojects/argparse-2.3/include/argparse/argparse.hpp:857:34:   required from here
../subprojects/argparse-2.3/include/argparse/argparse.hpp:352:47: warning: unused parameter ‘unused’ [-Wunused-parameter]
  352 |                     std::index_sequence<I...> unused)
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~

We can add the [maybe_unused] attribute from C++17, but I think removing the lint makes more sense, since leaving the parameter name blank is a C++ feature that it makes sense to take advantage of in this case, IMO.

@ericonr
Copy link
Contributor Author

ericonr commented Apr 13, 2022

From https://google.github.io/styleguide/cppguide.html#Function_Declarations_and_Definitions , which explains the rationale for this lint:

A parameter name may be omitted only if the parameter is not used in the function's definition.

It seems clang-tidy v12 did not implement the lint correctly, but v13 did, as noticed in the commit message (but was attributed to a bug in v13 instead of being correct):

Note that clang-tidy v12 appears to detect unnamed parameters in lambdas,
while clang-tidy v13 does not.

@skrobinson
Copy link
Contributor

I like documenting that the parameter is intentionally unused by the function, rather than just leaving it out. How does the following pattern work for you?

-          .action([&](const auto &unused) {
+          .action([&](const auto &/*unused*/) {

This passes with clang-tidy v13 and the current config file. For now, v12 is not linting PR.

@ericonr
Copy link
Contributor Author

ericonr commented Apr 16, 2022

I like that pattern!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants