rigtorp / MPMCQueue

A bounded multi-producer multi-consumer concurrent queue written in C++11
MIT License
1.15k stars 159 forks source link

std::aligned_storage is deprecated #49

Open anders-wind opened 2 months ago

anders-wind commented 2 months ago

In c++23, std::aligned_storage is being deprecated (The proposed alternative is to use std::array<std::byte>). This causes compiler errors with for example clang-17 or 18 with c++23 flags see below.

...
[build] build/vcpkg_installed/x64-linux/include/rigtorp/MPMCQueue.h:108:17: error: 'aligned_storage<4, 4>' is deprecated [-Werror,-Wdeprecated-declarations]
[build]   108 |   typename std::aligned_storage<sizeof(T), alignof(T)>::type storage;
[build]       |                 ^
[build] /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/allocator.h:193:38: note: in instantiation of template class 'rigtorp::mpmc::Slot<int>' requested here
[build]   193 |             if (__builtin_mul_overflow(__n, sizeof(_Tp), &__n))
[build]       |                                             ^
[build] build/vcpkg_installed/x64-linux/include/rigtorp/MPMCQueue.h:129:25: note: in instantiation of member function 'std::allocator<rigtorp::mpmc::Slot<int>>::allocate' requested here
[build]   129 |     slots_ = allocator_.allocate(capacity_ + 1);
[build]       |                         ^
[build] utilities/include/utilities/parallel_helpers.h:28:18: note: in instantiation of member function 'rigtorp::mpmc::Queue<int>::Queue' requested here
[build]    28 |     auto tasks = rigtorp::MPMCQueue<TaskArgT>(n_tasks);
[build]       |                  ^
...
[build] 1 error generated.

We are getting MPMCqueue with the newest release of vcpkg. To work around this, we just add warning suppressions around it, but getting a real fix for this would be nice.

brmarkus commented 2 months ago

Does "compiling with clang-18 or 17" mean you are compiling with "C++23"? (found e.g. this "https://stackoverflow.com/questions/71828288/why-is-stdaligned-storage-to-be-deprecated-in-c23-and-what-to-use-instead")

anders-wind commented 2 months ago

Does "compiling with clang-18 or 17" mean you are compiling with "C++23"? (found e.g. this "https://stackoverflow.com/questions/71828288/why-is-stdaligned-storage-to-be-deprecated-in-c23-and-what-to-use-instead")

Yes we are running with c++23 flags, so yes the deprecation of std::alligned_storage in c++ 23 is the causing issue, not clang-18 or 17 per se. I just wanted to include the information.

Ill improve the wording of the issue