Skip to content

Commit f01f35d

Browse files
authored
Remove std::aligned_storage usage from tests (#1971)
1 parent a5967f0 commit f01f35d

8 files changed

+48
-29
lines changed

test/common/concurrent_ordered_common.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
Copyright (c) 2019-2021 Intel Corporation
3+
Copyright (c) 2026 UXL Foundation Contributors
34
45
Licensed under the Apache License, Version 2.0 (the "License");
56
you may not use this file except in compliance with the License.
@@ -163,19 +164,19 @@ struct OrderedMoveTraitsBase {
163164
static constexpr std::size_t expected_number_of_items_to_allocate_for_steal_move = 584; // TODO: remove allocation of dummy_node
164165

165166
template <typename OrderedType, typename Iterator>
166-
static OrderedType& construct_container( typename std::aligned_storage<sizeof(OrderedType)>::type& storage,
167+
static OrderedType& construct_container( utils::UninitializedStorage<OrderedType>& storage,
167168
Iterator begin, Iterator end )
168169
{
169-
OrderedType* ptr = reinterpret_cast<OrderedType*>(&storage);
170+
OrderedType* ptr = &storage;
170171
new (ptr) OrderedType(begin, end);
171172
return *ptr;
172173
}
173174

174175
template <typename OrderedType, typename Iterator, typename Allocator>
175-
static OrderedType& construct_container( typename std::aligned_storage<sizeof(OrderedType)>::type& storage,
176+
static OrderedType& construct_container( utils::UninitializedStorage<OrderedType>& storage,
176177
Iterator begin, Iterator end, const Allocator& alloc )
177178
{
178-
OrderedType* ptr = reinterpret_cast<OrderedType*>(&storage);
179+
OrderedType* ptr = &storage;
179180
new (ptr) OrderedType(begin, end, typename OrderedType::key_compare(), alloc);
180181
return *ptr;
181182
}

test/common/concurrent_unordered_common.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
Copyright (c) 2005-2023 Intel Corporation
3+
Copyright (c) 2026 UXL Foundation Contributors
34
45
Licensed under the Apache License, Version 2.0 (the "License");
56
you may not use this file except in compliance with the License.
@@ -117,19 +118,19 @@ struct UnorderedMoveTraitsBase {
117118
static constexpr std::size_t expected_number_of_items_to_allocate_for_steal_move = 3; // TODO: check
118119

119120
template <typename UnorderedType, typename Iterator>
120-
static UnorderedType& construct_container( typename std::aligned_storage<sizeof(UnorderedType)>::type& storage,
121+
static UnorderedType& construct_container( utils::UninitializedStorage<UnorderedType>& storage,
121122
Iterator begin, Iterator end )
122123
{
123-
UnorderedType* ptr = reinterpret_cast<UnorderedType*>(&storage);
124+
UnorderedType* ptr = &storage;
124125
new (ptr) UnorderedType(begin, end);
125126
return *ptr;
126127
}
127128

128129
template <typename UnorderedType, typename Iterator, typename Allocator>
129-
static UnorderedType& construct_container( typename std::aligned_storage<sizeof(UnorderedType)>::type& storage,
130-
Iterator begin, Iterator end, const Allocator& alloc )
130+
static UnorderedType& construct_container( utils::UninitializedStorage<UnorderedType>& storage,
131+
Iterator begin, Iterator end, const Allocator& alloc )
131132
{
132-
UnorderedType* ptr = reinterpret_cast<UnorderedType*>(&storage);
133+
UnorderedType* ptr = &storage;
133134
new (ptr) UnorderedType(begin, end, /*bucket_count = */4, alloc);
134135
return *ptr;
135136
}

test/common/container_move_support.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
Copyright (c) 2005-2021 Intel Corporation
3+
Copyright (c) 2026 UXL Foundation Contributors
34
45
Licensed under the Apache License, Version 2.0 (the "License");
56
you may not use this file except in compliance with the License.
@@ -25,6 +26,7 @@
2526
#include <algorithm>
2627
#include "custom_allocators.h"
2728
#include "state_trackable.h"
29+
#include "utils.h"
2830

2931
namespace move_support_tests {
3032

@@ -359,13 +361,13 @@ struct ArenaAllocatorFixture {
359361
using allocator_type = ArenaAllocator<T, POCMA>;
360362
using arena_data_type = typename allocator_type::arena_data_type;
361363

362-
std::vector<typename std::aligned_storage<sizeof(T)>::type> storage;
364+
std::vector<utils::UninitializedStorage<T>> storage;
363365
arena_data_type arena_data;
364366
allocator_type allocator;
365367

366368
ArenaAllocatorFixture( std::size_t size_to_allocate )
367369
: storage(size_to_allocate),
368-
arena_data(reinterpret_cast<T*>(&storage.front()), storage.size()),
370+
arena_data(&storage.front(), storage.size()),
369371
allocator(arena_data) {}
370372

371373
ArenaAllocatorFixture( const ArenaAllocatorFixture& ) = delete;
@@ -427,7 +429,7 @@ struct MoveFixture {
427429
static constexpr std::size_t default_container_size = 100;
428430
const std::size_t container_size;
429431

430-
typename std::aligned_storage<sizeof(container_type)>::type source_storage;
432+
utils::UninitializedStorage<container_type> source_storage;
431433
container_type& source;
432434

433435
MemoryLocations locations;

test/common/utils.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
Copyright (c) 2005-2022 Intel Corporation
3+
Copyright (c) 2026 UXL Foundation Contributors
34
45
Licensed under the Apache License, Version 2.0 (the "License");
56
you may not use this file except in compliance with the License.
@@ -475,6 +476,17 @@ class LifeTrackableObject {
475476
};
476477
std::unordered_set<const LifeTrackableObject*> LifeTrackableObject::alive_objects{};
477478

479+
template <typename T>
480+
class UninitializedStorage {
481+
union {
482+
T m_value;
483+
};
484+
public:
485+
UninitializedStorage() {}
486+
~UninitializedStorage() {}
487+
T* operator&() { return &m_value; }
488+
};
489+
478490
} // namespace utils
479491

480492
#endif // __TBB_test_common_utils_H

test/conformance/conformance_concurrent_hash_map.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
Copyright (c) 2005-2024 Intel Corporation
3+
Copyright (c) 2026 UXL Foundation Contributors
34
45
Licensed under the Apache License, Version 2.0 (the "License");
56
you may not use this file except in compliance with the License.
@@ -548,15 +549,15 @@ void TestExceptions() {
548549

549550
struct default_container_traits {
550551
template <typename container_type, typename iterator_type>
551-
static container_type& construct_container(typename std::aligned_storage<sizeof(container_type)>::type& storage, iterator_type begin, iterator_type end){
552-
container_type* ptr = reinterpret_cast<container_type*>(&storage);
552+
static container_type& construct_container(utils::UninitializedStorage<container_type>& storage, iterator_type begin, iterator_type end){
553+
container_type* ptr = &storage;
553554
new (ptr) container_type(begin, end);
554555
return *ptr;
555556
}
556557

557558
template <typename container_type, typename iterator_type, typename allocator_type>
558-
static container_type& construct_container(typename std::aligned_storage<sizeof(container_type)>::type& storage, iterator_type begin, iterator_type end, allocator_type const& a){
559-
container_type* ptr = reinterpret_cast<container_type*>(&storage);
559+
static container_type& construct_container(utils::UninitializedStorage<container_type>& storage, iterator_type begin, iterator_type end, allocator_type const& a){
560+
container_type* ptr = &storage;
560561
new (ptr) container_type(begin, end, a);
561562
return *ptr;
562563
}

test/conformance/conformance_concurrent_vector.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
Copyright (c) 2005-2023 Intel Corporation
3+
Copyright (c) 2026 UXL Foundation Contributors
34
45
Licensed under the Apache License, Version 2.0 (the "License");
56
you may not use this file except in compliance with the License.
@@ -648,15 +649,15 @@ void TestSerialMoveInShrinkToFit(){
648649

649650
struct default_container_traits {
650651
template <typename container_type, typename iterator_type>
651-
static container_type& construct_container(typename std::aligned_storage<sizeof(container_type)>::type& storage, iterator_type begin, iterator_type end){
652-
container_type* ptr = reinterpret_cast<container_type*>(&storage);
652+
static container_type& construct_container(utils::UninitializedStorage<container_type>& storage, iterator_type begin, iterator_type end){
653+
container_type* ptr = &storage;
653654
new (ptr) container_type(begin, end);
654655
return *ptr;
655656
}
656657

657658
template <typename container_type, typename iterator_type, typename allocator_type>
658-
static container_type& construct_container(typename std::aligned_storage<sizeof(container_type)>::type& storage, iterator_type begin, iterator_type end, allocator_type const& a){
659-
container_type* ptr = reinterpret_cast<container_type*>(&storage);
659+
static container_type& construct_container(utils::UninitializedStorage<container_type>& storage, iterator_type begin, iterator_type end, allocator_type const& a){
660+
container_type* ptr = &storage;
660661
new (ptr) container_type(begin, end, a);
661662
return *ptr;
662663
}

test/tbb/test_concurrent_hash_map.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
Copyright (c) 2005-2025 Intel Corporation
3-
Copyright (c) 2025 UXL Foundation Contributors
3+
Copyright (c) 2025-2026 UXL Foundation Contributors
44
55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.
@@ -473,15 +473,15 @@ void TestInternalFastFind() {
473473

474474
struct default_container_traits {
475475
template <typename container_type, typename iterator_type>
476-
static container_type& construct_container(typename std::aligned_storage<sizeof(container_type)>::type& storage, iterator_type begin, iterator_type end){
477-
container_type* ptr = reinterpret_cast<container_type*>(&storage);
476+
static container_type& construct_container(utils::UninitializedStorage<container_type>& storage, iterator_type begin, iterator_type end){
477+
container_type* ptr = &storage;
478478
new (ptr) container_type(begin, end);
479479
return *ptr;
480480
}
481481

482482
template <typename container_type, typename iterator_type, typename allocator_type>
483-
static container_type& construct_container(typename std::aligned_storage<sizeof(container_type)>::type& storage, iterator_type begin, iterator_type end, allocator_type const& a){
484-
container_type* ptr = reinterpret_cast<container_type*>(&storage);
483+
static container_type& construct_container(utils::UninitializedStorage<container_type>& storage, iterator_type begin, iterator_type end, allocator_type const& a){
484+
container_type* ptr = &storage;
485485
new (ptr) container_type(begin, end, a);
486486
return *ptr;
487487
}

test/tbb/test_concurrent_vector.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
Copyright (c) 2005-2024 Intel Corporation
3+
Copyright (c) 2026 UXL Foundation Contributors
34
45
Licensed under the Apache License, Version 2.0 (the "License");
56
you may not use this file except in compliance with the License.
@@ -67,15 +68,15 @@ void TestRangeBasedFor(){
6768

6869
struct default_container_traits {
6970
template <typename container_type, typename iterator_type>
70-
static container_type& construct_container(typename std::aligned_storage<sizeof(container_type)>::type& storage, iterator_type begin, iterator_type end){
71-
container_type* ptr = reinterpret_cast<container_type*>(&storage);
71+
static container_type& construct_container(utils::UninitializedStorage<container_type>& storage, iterator_type begin, iterator_type end){
72+
container_type* ptr = &storage;
7273
new (ptr) container_type(begin, end);
7374
return *ptr;
7475
}
7576

7677
template <typename container_type, typename iterator_type, typename allocator_type>
77-
static container_type& construct_container(typename std::aligned_storage<sizeof(container_type)>::type& storage, iterator_type begin, iterator_type end, allocator_type const& a){
78-
container_type* ptr = reinterpret_cast<container_type*>(&storage);
78+
static container_type& construct_container(utils::UninitializedStorage<container_type>& storage, iterator_type begin, iterator_type end, allocator_type const& a){
79+
container_type* ptr = &storage;
7980
new (ptr) container_type(begin, end, a);
8081
return *ptr;
8182
}

0 commit comments

Comments
 (0)