Skip to content

Conversation

@kou
Copy link
Member

@kou kou commented Jun 10, 2025

Client: cpp

C++17 deprecated std::iterator.

See
https://www.fluentcpp.com/2018/05/08/std-iterator-deprecated/

Prior to this change, compiling while targeting C++17 or higher results in warnings.

  • Did you create an Apache Jira ticket? (Request account here, not required for trivial changes)
  • If a ticket exists: Does your pull request title follow the pattern "THRIFT-NNNN: describe my issue"?
  • Did you squash your changes to a single commit? (not required, but preferred)
  • Did you do your best to avoid breaking changes? If one was needed, did you label the Jira ticket with "Breaking-Change"?
  • If your change does not involve any code, include [skip ci] anywhere in the commit message to free up build resources.

Client: cpp

C++17 deprecated std::iterator.

See
https://www.fluentcpp.com/2018/05/08/std-iterator-deprecated/

Prior to this change, compiling while targeting C++17 or higher results
in warnings.
@kou
Copy link
Member Author

kou commented Jun 10, 2025

NOTE: The commit content is same as #2778 .

@Jens-G Jens-G added the c++ label Jun 10, 2025
@Jens-G Jens-G merged commit ae342c2 into apache:master Jun 10, 2025
20 of 29 checks passed
@kou kou deleted the std-iterator branch June 10, 2025 20:57
@CJCombrink
Copy link
Contributor

@kou Thanks for the work but do you have any idea what goes wrong here:
https://github.com/CJCombrink/thrift/actions/runs/15618763795/job/43998286079

libtool: compile:  g++ -std=c++11 -DHAVE_CONFIG_H -I/usr/include -I../../../lib/cpp/src -I../../../lib/cpp/src/thrift -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I. -Wall -Wextra -pedantic -g -O2 -c gen-cpp/DebugProtoTest_types.cpp  -fPIC -DPIC -o gen-cpp/.libs/DebugProtoTest_types.o
In file included from /usr/include/c++/13/map:63,
                 from ../../../lib/cpp/src/thrift/Thrift.h:38,
                 from gen-cpp/AnnotationTest_types.h:12,
                 from gen-cpp/AnnotationTest_types.cpp:7:
/usr/include/c++/13/bits/stl_map.h: In instantiation of 'std::map<_Key, _Tp, _Compare, _Alloc>::map(_InputIterator, _InputIterator) [with _InputIterator = apache::thrift::TEnumIterator; _Key = int; _Tp = const char*; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, const char*> >]':
gen-cpp/AnnotationTest_types.cpp:34:184:   required from here
/usr/include/c++/13/bits/stl_map.h:287:38: error: no matching function for call to 'std::_Rb_tree<int, std::pair<const int, const char*>, std::_Select1st<std::pair<const int, const char*> >, std::less<int>, std::allocator<std::pair<const int, const char*> > >::_M_insert_range_unique(apache::thrift::TEnumIterator&, apache::thrift::TEnumIterator&)'
  287 |         { _M_t._M_insert_range_unique(__first, __last); }
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/map:62:
/usr/include/c++/13/bits/stl_tree.h:1100:9: note: candidate: 'template<class _InputIterator> std::__enable_if_t<std::is_same<_Val, typename std::iterator_traits<_InputIterator>::value_type>::value> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_range_unique(_InputIterator, _InputIterator) [with _Key = int; _Val = std::pair<const int, const char*>; _KeyOfValue = std::_Select1st<std::pair<const int, const char*> >; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, const char*> >]'
 1100 |         _M_insert_range_unique(_InputIterator __first, _InputIterator __last)
      |         ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_tree.h:1100:9: note:   template argument deduction/substitution failed:
/usr/include/c++/13/bits/stl_tree.h: In substitution of 'template<class _InputIterator> std::__enable_if_t<std::is_same<std::pair<const int, const char*>, typename std::iterator_traits< <template-parameter-1-1> >::value_type>::value, void> std::_Rb_tree<int, std::pair<const int, const char*>, std::_Select1st<std::pair<const int, const char*> >, std::less<int>, std::allocator<std::pair<const int, const char*> > >::_M_insert_range_unique(_InputIterator, _InputIterator) [with _InputIterator = apache::thrift::TEnumIterator]':
/usr/include/c++/13/bits/stl_map.h:287:31:   required from 'std::map<_Key, _Tp, _Compare, _Alloc>::map(_InputIterator, _InputIterator) [with _InputIterator = apache::thrift::TEnumIterator; _Key = int; _Tp = const char*; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, const char*> >]'
gen-cpp/AnnotationTest_types.cpp:34:184:   required from here
/usr/include/c++/13/bits/stl_tree.h:1100:9: error: no type named 'value_type' in 'struct std::iterator_traits<apache::thrift::TEnumIterator>'
/usr/include/c++/13/bits/stl_map.h: In instantiation of 'std::map<_Key, _Tp, _Compare, _Alloc>::map(_InputIterator, _InputIterator) [with _InputIterator = apache::thrift::TEnumIterator; _Key = int; _Tp = const char*; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, const char*> >]':
gen-cpp/AnnotationTest_types.cpp:34:184:   required from here
/usr/include/c++/13/bits/stl_tree.h:1109:9: note: candidate: 'template<class _InputIterator> std::__enable_if_t<(! std::is_same<_Val, typename std::iterator_traits<_InputIterator>::value_type>::value)> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_range_unique(_InputIterator, _InputIterator) [with _Key = int; _Val = std::pair<const int, const char*>; _KeyOfValue = std::_Select1st<std::pair<const int, const char*> >; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, const char*> >]'
 1109 |         _M_insert_range_unique(_InputIterator __first, _InputIterator __last)
      |         ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_tree.h:1109:9: note:   template argument deduction/substitution failed:
/usr/include/c++/13/bits/stl_tree.h: In substitution of 'template<class _InputIterator> std::__enable_if_t<(! std::is_same<std::pair<const int, const char*>, typename std::iterator_traits< <template-parameter-1-1> >::value_type>::value), void> std::_Rb_tree<int, std::pair<const int, const char*>, std::_Select1st<std::pair<const int, const char*> >, std::less<int>, std::allocator<std::pair<const int, const char*> > >::_M_insert_range_unique(_InputIterator, _InputIterator) [with _InputIterator = apache::thrift::TEnumIterator]':
/usr/include/c++/13/bits/stl_map.h:287:31:   required from 'std::map<_Key, _Tp, _Compare, _Alloc>::map(_InputIterator, _InputIterator) [with _InputIterator = apache::thrift::TEnumIterator; _Key = int; _Tp = const char*; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, const char*> >]'
gen-cpp/AnnotationTest_types.cpp:34:184:   required from here
/usr/include/c++/13/bits/stl_tree.h:1108:59: error: no type named 'value_type' in 'struct std::iterator_traits<apache::thrift::TEnumIterator>'
 1108 |         __enable_if_t<!__same_value_type<_InputIterator>::value>
      |                                                           ^~~~~
make[2]: *** [Makefile:1496: gen-cpp/AnnotationTest_types.lo] Error 1
make[2]: *** Waiting for unfinished jobs....
In file included from /usr/include/c++/13/map:63,
                 from ../../../lib/cpp/src/thrift/Thrift.h:38,
                 from gen-cpp/DebugProtoTest_types.h:12,
                 from gen-cpp/DebugProtoTest_types.cpp:7:
/usr/include/c++/13/bits/stl_map.h: In instantiation of 'std::map<_Key, _Tp, _Compare, _Alloc>::map(_InputIterator, _InputIterator) [with _InputIterator = apache::thrift::TEnumIterator; _Key = int; _Tp = const char*; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, const char*> >]':
gen-cpp/DebugProtoTest_types.cpp:24:184:   required from here
/usr/include/c++/13/bits/stl_map.h:287:38: error: no matching function for call to 'std::_Rb_tree<int, std::pair<const int, const char*>, std::_Select1st<std::pair<const int, const char*> >, std::less<int>, std::allocator<std::pair<const int, const char*> > >::_M_insert_range_unique(apache::thrift::TEnumIterator&, apache::thrift::TEnumIterator&)'
  287 |         { _M_t._M_insert_range_unique(__first, __last); }
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/map:62:
/usr/include/c++/13/bits/stl_tree.h:1100:9: note: candidate: 'template<class _InputIterator> std::__enable_if_t<std::is_same<_Val, typename std::iterator_traits<_InputIterator>::value_type>::value> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_range_unique(_InputIterator, _InputIterator) [with _Key = int; _Val = std::pair<const int, const char*>; _KeyOfValue = std::_Select1st<std::pair<const int, const char*> >; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, const char*> >]'
 1100 |         _M_insert_range_unique(_InputIterator __first, _InputIterator __last)
      |         ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_tree.h:1100:9: note:   template argument deduction/substitution failed:
/usr/include/c++/13/bits/stl_tree.h: In substitution of 'template<class _InputIterator> std::__enable_if_t<std::is_same<std::pair<const int, const char*>, typename std::iterator_traits< <template-parameter-1-1> >::value_type>::value, void> std::_Rb_tree<int, std::pair<const int, const char*>, std::_Select1st<std::pair<const int, const char*> >, std::less<int>, std::allocator<std::pair<const int, const char*> > >::_M_insert_range_unique(_InputIterator, _InputIterator) [with _InputIterator = apache::thrift::TEnumIterator]':
/usr/include/c++/13/bits/stl_map.h:287:31:   required from 'std::map<_Key, _Tp, _Compare, _Alloc>::map(_InputIterator, _InputIterator) [with _InputIterator = apache::thrift::TEnumIterator; _Key = int; _Tp = const char*; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, const char*> >]'
gen-cpp/DebugProtoTest_types.cpp:24:184:   required from here
/usr/include/c++/13/bits/stl_tree.h:1100:9: error: no type named 'value_type' in 'struct std::iterator_traits<apache::thrift::TEnumIterator>'
/usr/include/c++/13/bits/stl_map.h: In instantiation of 'std::map<_Key, _Tp, _Compare, _Alloc>::map(_InputIterator, _InputIterator) [with _InputIterator = apache::thrift::TEnumIterator; _Key = int; _Tp = const char*; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, const char*> >]':
gen-cpp/DebugProtoTest_types.cpp:24:184:   required from here
/usr/include/c++/13/bits/stl_tree.h:1109:9: note: candidate: 'template<class _InputIterator> std::__enable_if_t<(! std::is_same<_Val, typename std::iterator_traits<_InputIterator>::value_type>::value)> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_range_unique(_InputIterator, _InputIterator) [with _Key = int; _Val = std::pair<const int, const char*>; _KeyOfValue = std::_Select1st<std::pair<const int, const char*> >; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, const char*> >]'
 1109 |         _M_insert_range_unique(_InputIterator __first, _InputIterator __last)
      |         ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_tree.h:1109:9: note:   template argument deduction/substitution failed:
/usr/include/c++/13/bits/stl_tree.h: In substitution of 'template<class _InputIterator> std::__enable_if_t<(! std::is_same<std::pair<const int, const char*>, typename std::iterator_traits< <template-parameter-1-1> >::value_type>::value), void> std::_Rb_tree<int, std::pair<const int, const char*>, std::_Select1st<std::pair<const int, const char*> >, std::less<int>, std::allocator<std::pair<const int, const char*> > >::_M_insert_range_unique(_InputIterator, _InputIterator) [with _InputIterator = apache::thrift::TEnumIterator]':
/usr/include/c++/13/bits/stl_map.h:287:31:   required from 'std::map<_Key, _Tp, _Compare, _Alloc>::map(_InputIterator, _InputIterator) [with _InputIterator = apache::thrift::TEnumIterator; _Key = int; _Tp = const char*; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, const char*> >]'
gen-cpp/DebugProtoTest_types.cpp:24:184:   required from here
/usr/include/c++/13/bits/stl_tree.h:1108:59: error: no type named 'value_type' in 'struct std::iterator_traits<apache::thrift::TEnumIterator>'
 1108 |         __enable_if_t<!__same_value_type<_InputIterator>::value>
      |                                                           ^~~~~
make[2]: *** [Makefile:1496: gen-cpp/DebugProtoTest_types.lo] Error 1

Looks related

@CJCombrink CJCombrink mentioned this pull request Jun 12, 2025
5 tasks
@CJCombrink
Copy link
Contributor

From some reading (eg. std::iterator is deprecated: Why, What It Was, and What to Use Instead) it seems like all 5 options must be specified when replacing the deprecated std::iterator

This is confirmed in this change: CJCombrink@2dd5c9d
(action

@kou
Copy link
Member Author

kou commented Jun 13, 2025

Sorry... You're right. We should have defined difference_type, pointer and reference too...
Thanks for fixing it in #3167.

@CJCombrink
Copy link
Contributor

@kou No worries, thanks for initiating this fix 👍

@mhlakhani mhlakhani mentioned this pull request Jul 27, 2025
5 tasks
@mhlakhani
Copy link
Contributor

I split out the build fix into this PR (thank you @CJCombrink for doing the real work!) #3182 -- I was running into issues.

mhlakhani added a commit that referenced this pull request Aug 2, 2025
PR #3165 broke the build with c++11.

I split out the compile time fix from https://github.com/apache/thrift/pull/3167/files#diff-d8d7400cdf01511c2ad2df7caf958173c2e96e8633271709c9b0b5cd8e89215c to ensure we have a clean trunk (so I can have other changes on top). I can't take credit for the fixes.

I verified this compiles with gcc, clang (on c++11) and also on clang with c++1z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants