Skip to content

Commit 649340b

Browse files
authored
Merge pull request #195 from RcppCore/bugfix/std-iterator-warnings
avoid using std::iterator
2 parents 60406d2 + 22e579e commit 649340b

File tree

7 files changed

+64
-16
lines changed

7 files changed

+64
-16
lines changed

src/tbb/include/tbb/compat/iterator.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
#ifndef TBB_COMPAT_ITERATOR_H
3+
#define TBB_COMPAT_ITERATOR_H
4+
5+
#include <cstddef>
6+
7+
#include <iterator>
8+
9+
namespace tbb {
10+
11+
template <
12+
typename Category,
13+
typename T,
14+
typename Distance = std::ptrdiff_t,
15+
typename Pointer = T*,
16+
typename Reference = T&
17+
> struct iterator
18+
{
19+
using iterator_category = Category;
20+
using value_type = T;
21+
using difference_type = Distance;
22+
using pointer = Pointer;
23+
using reference = Reference;
24+
};
25+
26+
} // end namespace tbb
27+
28+
#endif
29+

src/tbb/include/tbb/concurrent_hash_map.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <cstring> // Need std::memset
2424
#include __TBB_STD_SWAP_HEADER
2525

26+
#include "compat/iterator.h"
2627
#include "tbb_allocator.h"
2728
#include "spin_rw_mutex.h"
2829
#include "atomic.h"
@@ -340,7 +341,7 @@ namespace interface5 {
340341
@ingroup containers */
341342
template<typename Container, typename Value>
342343
class hash_map_iterator
343-
: public std::iterator<std::forward_iterator_tag,Value>
344+
: public tbb::iterator<std::forward_iterator_tag,Value>
344345
{
345346
typedef Container map_type;
346347
typedef typename Container::node node;

src/tbb/include/tbb/enumerable_thread_specific.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#ifndef __TBB_enumerable_thread_specific_H
1818
#define __TBB_enumerable_thread_specific_H
1919

20+
#include "compat/iterator.h"
21+
2022
#include "atomic.h"
2123
#include "concurrent_vector.h"
2224
#include "tbb_thread.h"
@@ -296,7 +298,7 @@ namespace interface6 {
296298
class enumerable_thread_specific_iterator
297299
#if defined(_WIN64) && defined(_MSC_VER)
298300
// Ensure that Microsoft's internal template function _Val_type works correctly.
299-
: public std::iterator<std::random_access_iterator_tag,Value>
301+
: public tbb::iterator<std::random_access_iterator_tag,Value>
300302
#endif /* defined(_WIN64) && defined(_MSC_VER) */
301303
{
302304
//! current position in the concurrent_vector
@@ -458,7 +460,7 @@ namespace interface6 {
458460
template<typename SegmentedContainer, typename Value >
459461
class segmented_iterator
460462
#if defined(_WIN64) && defined(_MSC_VER)
461-
: public std::iterator<std::input_iterator_tag, Value>
463+
: public tbb::iterator<std::input_iterator_tag, Value>
462464
#endif
463465
{
464466
template<typename C, typename T, typename U>

src/tbb/include/tbb/internal/_concurrent_queue_impl.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#error Do not #include this internal file directly; use public TBB headers instead.
2222
#endif
2323

24+
#include "../compat/iterator.h"
25+
2426
#include "../tbb_stddef.h"
2527
#include "../tbb_machine.h"
2628
#include "../atomic.h"
@@ -741,7 +743,7 @@ template<typename T> struct tbb_remove_cv<const volatile T> {typedef T type;};
741743
@ingroup containers */
742744
template<typename Container, typename Value>
743745
class concurrent_queue_iterator: public concurrent_queue_iterator_base_v3<typename tbb_remove_cv<Value>::type>,
744-
public std::iterator<std::forward_iterator_tag,Value> {
746+
public tbb::iterator<std::forward_iterator_tag,Value> {
745747
#if !__TBB_TEMPLATE_FRIENDS_BROKEN
746748
template<typename T, class A>
747749
friend class ::tbb::strict_ppl::concurrent_queue;
@@ -1000,7 +1002,7 @@ typedef concurrent_queue_iterator_base_v3 concurrent_queue_iterator_base;
10001002
@ingroup containers */
10011003
template<typename Container, typename Value>
10021004
class concurrent_queue_iterator: public concurrent_queue_iterator_base,
1003-
public std::iterator<std::forward_iterator_tag,Value> {
1005+
public tbb::iterator<std::forward_iterator_tag,Value> {
10041006

10051007
#if !__TBB_TEMPLATE_FRIENDS_BROKEN
10061008
template<typename T, class A>

src/tbb/include/tbb/internal/_concurrent_unordered_impl.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include <cstring> // Need std::memset
3333
#include __TBB_STD_SWAP_HEADER
3434

35+
#include "../compat/iterator.h"
36+
3537
#include "../atomic.h"
3638
#include "../tbb_exception.h"
3739
#include "../tbb_allocator.h"
@@ -64,7 +66,7 @@ class concurrent_unordered_base;
6466

6567
// Forward list iterators (without skipping dummy elements)
6668
template<class Solist, typename Value>
67-
class flist_iterator : public std::iterator<std::forward_iterator_tag, Value>
69+
class flist_iterator : public tbb::iterator<std::forward_iterator_tag, Value>
6870
{
6971
template <typename T, typename Allocator>
7072
friend class split_ordered_list;

src/tbb/src/tbbmalloc/proxy.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@
1414
limitations under the License.
1515
*/
1616

17+
#ifdef __GNUC__
18+
# if __GNUC__ >= 12
19+
# define TBB_ALIAS(x) __attribute__((alias(#x), copy(x)))
20+
# endif
21+
#endif
22+
23+
#ifndef TBB_ALIAS
24+
# define TBB_ALIAS(x) __attribute__((alias(#x)))
25+
#endif
26+
1727
#if __linux__ && !__ANDROID__
1828
// include <bits/c++config.h> indirectly so that <cstdlib> is not included
1929
#include <cstddef>
@@ -146,7 +156,7 @@ static inline void initPageSize()
146156
1) detection that the proxy library is loaded
147157
2) check that dlsym("malloc") found something different from our replacement malloc
148158
*/
149-
extern "C" void *__TBB_malloc_proxy(size_t) __attribute__ ((alias ("malloc")));
159+
extern "C" void *__TBB_malloc_proxy(size_t) TBB_ALIAS(malloc);
150160

151161
static void *orig_msize;
152162

@@ -285,19 +295,19 @@ struct mallinfo mallinfo() __THROW
285295
// Android doesn't have malloc_usable_size, provide it to be compatible
286296
// with Linux, in addition overload dlmalloc_usable_size() that presented
287297
// under Android.
288-
size_t dlmalloc_usable_size(const void *ptr) __attribute__ ((alias ("malloc_usable_size")));
298+
size_t dlmalloc_usable_size(const void *ptr) TBB_ALIAS(malloc_usable_size);
289299
#else // __ANDROID__
290300
// C11 function, supported starting GLIBC 2.16
291-
void *aligned_alloc(size_t alignment, size_t size) __attribute__ ((alias ("memalign")));
301+
void *aligned_alloc(size_t alignment, size_t size) TBB_ALIAS(memalign);
292302
// Those non-standard functions are exported by GLIBC, and might be used
293303
// in conjunction with standard malloc/free, so we must ovberload them.
294304
// Bionic doesn't have them. Not removing from the linker scripts,
295305
// as absent entry points are ignored by the linker.
296-
void *__libc_malloc(size_t size) __attribute__ ((alias ("malloc")));
297-
void *__libc_calloc(size_t num, size_t size) __attribute__ ((alias ("calloc")));
298-
void *__libc_memalign(size_t alignment, size_t size) __attribute__ ((alias ("memalign")));
299-
void *__libc_pvalloc(size_t size) __attribute__ ((alias ("pvalloc")));
300-
void *__libc_valloc(size_t size) __attribute__ ((alias ("valloc")));
306+
void *__libc_malloc(size_t size) TBB_ALIAS(malloc);
307+
void *__libc_calloc(size_t num, size_t size) TBB_ALIAS(calloc);
308+
void *__libc_memalign(size_t alignment, size_t size) TBB_ALIAS(memalign);
309+
void *__libc_pvalloc(size_t size) TBB_ALIAS(pvalloc);
310+
void *__libc_valloc(size_t size) TBB_ALIAS(valloc);
301311

302312
// call original __libc_* to support naive replacement of free via __libc_free etc
303313
void __libc_free(void *ptr)

src/tbb/src/test/test_container_move_support.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "harness_allocator.h"
2323
#include "harness_state_trackable.h"
2424

25+
#include "tbb/compat/iterator.h"
26+
2527
#include "tbb/atomic.h"
2628
#include "tbb/aligned_space.h"
2729
#include "tbb/internal/_allocator_traits.h"
@@ -172,7 +174,7 @@ class FooIteratorBase {
172174
friend bool operator!=(const FooIteratorType & lhs, const FooIteratorType & rhs){ return !(lhs == rhs); }
173175
};
174176

175-
class FooIterator: public std::iterator<std::input_iterator_tag,FooWithAssign>, public FooIteratorBase<FooIterator> {
177+
class FooIterator: public tbb::iterator<std::input_iterator_tag,FooWithAssign>, public FooIteratorBase<FooIterator> {
176178
public:
177179
FooIterator(intptr_t x): FooIteratorBase<FooIterator>(x) {}
178180

@@ -181,7 +183,7 @@ class FooIterator: public std::iterator<std::input_iterator_tag,FooWithAssign>,
181183
}
182184
};
183185

184-
class FooPairIterator: public std::iterator<std::input_iterator_tag, std::pair<FooWithAssign,FooWithAssign> >, public FooIteratorBase<FooPairIterator> {
186+
class FooPairIterator: public tbb::iterator<std::input_iterator_tag, std::pair<FooWithAssign,FooWithAssign> >, public FooIteratorBase<FooPairIterator> {
185187
public:
186188
FooPairIterator(intptr_t x): FooIteratorBase<FooPairIterator>(x) {}
187189

0 commit comments

Comments
 (0)