Invalid initializer in `declare_group` when processing a list of options
The C++ option_group
produced when processing a list of options mistakenly generates an initializer_list
instead of a brace-enclosed initializer list
. This produces the following error when incorporating generated code into a project:
make
[ 11%] Built target fmt
[ 42%] Built target spdlog
[ 46%] Built target genopts_virtualenv
[ 53%] Built target network_engine
[ 61%] Built target utils
[ 65%] Building CXX object src/config/CMakeFiles/config.dir/settings.cpp.o
In file included from /home/amiranda/var/projects/scord/repo/src/config/settings.cpp:27:
/home/amiranda/var/projects/scord/repo/build/src/config/config_options.hpp:53:29: error: invalid initialization of reference of type ‘const std::initializer_list<std::pair<const std::__cxx11::basic_string<char>, file_options::option_schema> >&&’ from expression of type ‘file_options::OptionSchemaType’ {aka ‘std::pair<const std::__cxx11::basic_string<char>, file_options::option_schema>’}
53 | declare_option<bool>(
| ~~~~~~~~~~~~~~~~~~~~^
54 | keywords::use_syslog,
| ~~~~~~~~~~~~~~~~~~~~~
55 | opt_type::mandatory,
| ~~~~~~~~~~~~~~~~~~~~
56 | converter<bool>(parsers::parse_bool))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/amiranda/var/projects/scord/repo/src/config/file_options/file_options.hpp:28,
from /home/amiranda/var/projects/scord/repo/build/src/config/config_options.hpp:30,
from /home/amiranda/var/projects/scord/repo/src/config/settings.cpp:27:
/home/amiranda/var/projects/scord/repo/src/config/file_options/schema.hpp:388:63: note: in passing argument 1 of ‘file_options::group_schema file_options::declare_group(const std::initializer_list<std::pair<const std::__cxx11::basic_string<char>, file_options::option_schema> >&&)’
388 | declare_group(const std::initializer_list<OptionSchemaType>&& args) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
In file included from /home/amiranda/var/projects/scord/repo/src/config/settings.cpp:27:
/home/amiranda/var/projects/scord/repo/build/src/config/config_options.hpp:94:2: error: invalid initialization of reference of type ‘const std::initializer_list<std::pair<const std::__cxx11::basic_string<char>, file_options::section_schema> >&&’ from expression of type ‘<brace-enclosed initializer list>’
94 | });
| ^
In file included from /home/amiranda/var/projects/scord/repo/src/config/file_options/file_options.hpp:28,
from /home/amiranda/var/projects/scord/repo/build/src/config/config_options.hpp:30,
from /home/amiranda/var/projects/scord/repo/src/config/settings.cpp:27:
/home/amiranda/var/projects/scord/repo/src/config/file_options/schema.hpp:408:63: note: in passing argument 1 of ‘file_options::file_schema file_options::declare_file(const std::initializer_list<std::pair<const std::__cxx11::basic_string<char>, file_options::section_schema> >&&)’
408 | declare_file(const std::initializer_list<SectionSchemaType>&& args) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
make[2]: *** [src/config/CMakeFiles/config.dir/build.make:97: src/config/CMakeFiles/config.dir/settings.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:415: src/config/CMakeFiles/config.dir/all] Error 2
make: *** [Makefile:130: all] Error 2
Edited by Alberto Miranda