Commit ffdaf3a
committed
add iterator_traits to ChildInstanstiablesIterator
I have seen the following compile error on g++-13 when trying to use
std::find_if with ChildInstanstiablesIterator:
[9/30] Building CXX object CMakeFiles/test_schema_node.dir/tests/schema_node.cpp.o
FAILED: [code=1] CMakeFiles/test_schema_node.dir/tests/schema_node.cpp.o
/usr/bin/g++-13 -DDOCTEST_CONFIG_SUPER_FAST_ASSERTS -I/home/tomas/zdrojaky/cesnet/libyang-cpp/include -I/home/tomas/zdrojaky/cesnet/libyang-cpp/build-gcc-asan -I/home/tomas/zdrojaky/cesnet/libyang-cpp/tests -I/home/tomas/zdrojaky/cesnet/libyang-cpp/src -I/home/tomas/zdrojaky/cesnet/libyang-cpp -isystem /home/tomas/zdrojaky/cesnet/build/prefixes/gcc-asan/include -Wall -Wextra -pedantic -Woverloaded-virtual -Wimplicit-fallthrough -Wsuggest-override -fsanitize=address,undefined -g -I/opt/boost1.88/include -std=gnu++23 -fvisibility=hidden -fvisibility-inlines-hidden -MD -MT CMakeFiles/test_schema_node.dir/tests/schema_node.cpp.o -MF CMakeFiles/test_schema_node.dir/tests/schema_node.cpp.o.d -o CMakeFiles/test_schema_node.dir/tests/schema_node.cpp.o -c /home/tomas/zdrojaky/cesnet/libyang-cpp/tests/schema_node.cpp
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/13.4.1/include/c++/string:51,
from /usr/lib/gcc/x86_64-pc-linux-gnu/13.4.1/include/c++/stdexcept:39,
from /usr/lib/gcc/x86_64-pc-linux-gnu/13.4.1/include/c++/system_error:43,
from /usr/lib/gcc/x86_64-pc-linux-gnu/13.4.1/include/c++/bits/fs_fwd.h:35,
from /usr/lib/gcc/x86_64-pc-linux-gnu/13.4.1/include/c++/filesystem:48,
from /home/tomas/zdrojaky/cesnet/libyang-cpp/include/libyang-cpp/Context.hpp:10,
from /home/tomas/zdrojaky/cesnet/libyang-cpp/tests/schema_node.cpp:10:
/usr/lib/gcc/x86_64-pc-linux-gnu/13.4.1/include/c++/bits/stl_algobase.h: In instantiation of ‘constexpr _Iterator std::__find_if(_Iterator, _Iterator, _Predicate) [with _Iterator = libyang::ChildInstanstiablesIterator; _Predicate = __gnu_cxx::__ops::_Iter_pred<DOCTEST_ANON_FUNC_2()::<lambda(const libyang::SchemaNode&)> >]’:
/usr/lib/gcc/x86_64-pc-linux-gnu/13.4.1/include/c++/bits/stl_algo.h:3923:28: required from ‘constexpr _IIter std::find_if(_IIter, _IIter, _Predicate) [with _IIter = libyang::ChildInstanstiablesIterator; _Predicate = DOCTEST_ANON_FUNC_2()::<lambda(const libyang::SchemaNode&)>]’
/home/tomas/zdrojaky/cesnet/libyang-cpp/tests/schema_node.cpp:269:17: required from here
/usr/lib/gcc/x86_64-pc-linux-gnu/13.4.1/include/c++/bits/stl_algobase.h:2117:23: error: no matching function for call to ‘__find_if(libyang::ChildInstanstiablesIterator&, libyang::ChildInstanstiablesIterator&, __gnu_cxx::__ops::_Iter_pred<DOCTEST_ANON_FUNC_2()::<lambda(const libyang::SchemaNode&)> >&, std::__iterator_traits<libyang::ChildInstanstiablesIterator, void>::iterator_category)’
2117 | return __find_if(__first, __last, __pred,
| ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
2118 | std::__iterator_category(__first));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/lib/gcc/x86_64-pc-linux-gnu/13.4.1/include/c++/bits/stl_algobase.h:2052:5: note: candidate: ‘template<class _InputIterator, class _Predicate> constexpr _InputIterator std::__find_if(_InputIterator, _InputIterator, _Predicate, input_iterator_tag)’
2052 | __find_if(_InputIterator __first, _InputIterator __last,
| ^~~~~~~~~
/usr/lib/gcc/x86_64-pc-linux-gnu/13.4.1/include/c++/bits/stl_algobase.h:2052:5: note: template argument deduction/substitution failed:
/usr/lib/gcc/x86_64-pc-linux-gnu/13.4.1/include/c++/bits/stl_algobase.h:2118:48: note: cannot convert ‘std::__iterator_category<libyang::ChildInstanstiablesIterator>(__first)’ (type ‘std::__iterator_traits<libyang::ChildInstanstiablesIterator, void>::iterator_category’ {aka ‘std::output_iterator_tag’}) to type ‘std::input_iterator_tag’
2118 | std::__iterator_category(__first));
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
/usr/lib/gcc/x86_64-pc-linux-gnu/13.4.1/include/c++/bits/stl_algobase.h:2064:5: note: candidate: ‘template<class _RandomAccessIterator, class _Predicate> constexpr _RandomAccessIterator std::__find_if(_RandomAccessIterator, _RandomAccessIterator, _Predicate, random_access_iterator_tag)’
2064 | __find_if(_RandomAccessIterator __first, _RandomAccessIterator __last,
| ^~~~~~~~~
/usr/lib/gcc/x86_64-pc-linux-gnu/13.4.1/include/c++/bits/stl_algobase.h:2064:5: note: template argument deduction/substitution failed:
/usr/lib/gcc/x86_64-pc-linux-gnu/13.4.1/include/c++/bits/stl_algobase.h:2118:48: note: cannot convert ‘std::__iterator_category<libyang::ChildInstanstiablesIterator>(__first)’ (type ‘std::__iterator_traits<libyang::ChildInstanstiablesIterator, void>::iterator_category’ {aka ‘std::output_iterator_tag’}) to type ‘std::random_access_iterator_tag’
2118 | std::__iterator_category(__first));
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
/usr/lib/gcc/x86_64-pc-linux-gnu/13.4.1/include/c++/bits/stl_algobase.h:2115:5: note: candidate: ‘template<class _Iterator, class _Predicate> constexpr _Iterator std::__find_if(_Iterator, _Iterator, _Predicate)’
2115 | __find_if(_Iterator __first, _Iterator __last, _Predicate __pred)
| ^~~~~~~~~
/usr/lib/gcc/x86_64-pc-linux-gnu/13.4.1/include/c++/bits/stl_algobase.h:2115:5: note: template argument deduction/substitution failed:
/usr/lib/gcc/x86_64-pc-linux-gnu/13.4.1/include/c++/bits/stl_algobase.h:2117:23: note: candidate expects 3 arguments, 4 provided
2117 | return __find_if(__first, __last, __pred,
| ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
2118 | std::__iterator_category(__first));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[21/30] Building CXX object CMakeFiles/test_data_node.dir/tests/data_node.cpp.o
ninja: build stopped: subcommand failed.
It seems our iterator category is wrongly deduced to
std::output_iterator_tag which does not work with std::find_if.
This patch adds the necessary typedefs to ChildInstanstiablesIterator
to make it a valid input iterator.
Interestingly, I have not seen this on my clang++-21, only on CI's
g++-13.
Change-Id: I0c4503cb3bd6166f3c79037ea2c4e3bed15200421 parent 4f2e502 commit ffdaf3a
2 files changed
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
19 | 25 | | |
20 | 26 | | |
21 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
264 | 264 | | |
265 | 265 | | |
266 | 266 | | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
267 | 271 | | |
268 | 272 | | |
269 | 273 | | |
| |||
0 commit comments