Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C++] std::aligned_storage is deprecated since C++23 #41536

Closed
vient opened this issue May 3, 2024 · 5 comments · Fixed by #45019
Closed

[C++] std::aligned_storage is deprecated since C++23 #41536

vient opened this issue May 3, 2024 · 5 comments · Fixed by #45019
Assignees
Milestone

Comments

@vient
Copy link

vient commented May 3, 2024

Describe the bug, including details regarding any error messages, version, and platform.

include/arrow/util/aligned_storage.h:140:17: warning: 'aligned_storage<16, 8>' is deprecated [-Wdeprecated-declarations]
  140 |   typename std::aligned_storage<sizeof(T), alignof(T)>::type data_;

Since it is in headers, it triggers when compiling user code with -std=c++23. Not a bug yet but it may be removed completely from C++26.

Seen with clang++-18.

Component(s)

C++

@vient vient added the Type: bug label May 3, 2024
@pitrou pitrou changed the title std::aligned_storage is deprecated since C++23 [C++] std::aligned_storage is deprecated since C++23 Sep 18, 2024
@pitrou
Copy link
Member

pitrou commented Sep 18, 2024

@vient We're using C++17, what is the suggested replacement for this?
I'll note that https://en.cppreference.com/w/cpp/types/aligned_storage is completed useless as it doesn't explain why it's deprecated.

@vient
Copy link
Author

vient commented Sep 18, 2024

https://stackoverflow.com/questions/71828288/why-is-stdaligned-storage-to-be-deprecated-in-c23-and-what-to-use-instead

// To replace std::aligned_storage
template <typename T>
class MyContainer {
private:
    //std::aligned_storage_t<sizeof(T), alignof(T)> t_buff;
    alignas(T) std::byte t_buff[sizeof(T)];
};

¯\_(ツ)_/¯

sjoubert added a commit to sjoubert/arrow that referenced this issue Dec 13, 2024
sjoubert added a commit to sjoubert/arrow that referenced this issue Dec 13, 2024
sjoubert added a commit to sjoubert/arrow that referenced this issue Dec 16, 2024
pitrou pushed a commit that referenced this issue Dec 18, 2024
…+23 (#45019)

This fixes #41536

### Rationale for this change

C++23 deprecates `std::aligned_storage`. The recommended alternative is an array of `std::byte` properly marked with `alignas()`. This change is compatible with C++17 and should also allow users to compile their code in C++23 mode without deprecation warnings.

### What changes are included in this PR?

This replaces `std::aligned_storage` as recommended and also removes a preprocessor define that was needed for MSVC.

However there is still [one usage](https://github.com/apache/arrow/blob/main/cpp/src/arrow/util/aligned_storage.h#L122-L139) of `std::aligned_storage` in a conditional to work around a GCC bug on i386:
* I don't know if `alignas` as a replacement would have the same bug as the original `alignof`
* The original bug seems to be fixed but I'm not sure in which GCC version and I also don't know which minimal version of GCC needs to be supported by the arrow project

If someone can confirm that it is ok to clean the code and use the same code unconditionally I'll update my changes.

* GitHub Issue: #41536

Authored-by: Sylvain Joubert <[email protected]>
Signed-off-by: Antoine Pitrou <[email protected]>
@pitrou pitrou added this to the 19.0.0 milestone Dec 18, 2024
@pitrou
Copy link
Member

pitrou commented Dec 18, 2024

Issue resolved by pull request 45019
#45019

@pitrou
Copy link
Member

pitrou commented Dec 18, 2024

@sjoubert Can you post a message here so that we can assign this issue to you?

@sjoubert
Copy link
Contributor

@sjoubert Can you post a message here so that we can assign this issue to you?

Present! Thanks for merging the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants