This is an automated email from the ASF dual-hosted git repository.
chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fory.git
The following commit(s) were added to refs/heads/main by this push:
new f2208857f fix(c++): replace deprecated std::aligned_storage (#3793)
f2208857f is described below
commit f2208857f2bbeb433b6a4d897cb603693cea8259
Author: Tal Risin <[email protected]>
AuthorDate: Mon Jun 29 10:03:03 2026 +0300
fix(c++): replace deprecated std::aligned_storage (#3793)
## Why?
`std::aligned_storage` is marked as deprecated in C++23, as can be seen
in the following compilation warning:
```
<project>/build/_deps/fory-src/cpp/fory/util/result.h:325:21: warning:
‘template<long unsigned int _Len, long unsigned int _Align> struct
std::aligned_storage’ is deprecated [-Wdeprecated-declarations]
325 | typename std::aligned_storage<sizeof(E), alignof(E)>::type;
| ^~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/bits/move.h:37,
from /usr/include/c++/13/bits/atomic_base.h:39,
from /usr/include/c++/13/atomic:41,
from <project source file>:
/usr/include/c++/13/type_traits:2099:5: note: declared here
2099 | aligned_storage
```
## What does this PR do?
Replaces `std::aligned_storage` with a `std::byte` array enclosed in an
aligned struct.
* `std::byte` is available since C++17 - the minimum supported version
by fory.
* `alignas` is available since C++11
This change shouldn't break anything.
## AI Contribution Checklist
- [ ] Substantial AI assistance was used in this PR: no
## Does this PR introduce any user-facing change?
- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?
---------
Co-authored-by: 慕白 <[email protected]>
Co-authored-by: Shawn Yang <[email protected]>
---
cpp/fory/util/result.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/cpp/fory/util/result.h b/cpp/fory/util/result.h
index 0fa5c91ba..96ca5009e 100644
--- a/cpp/fory/util/result.h
+++ b/cpp/fory/util/result.h
@@ -22,6 +22,7 @@
#include "fory/util/error.h"
#include "fory/util/logging.h"
#include "fory/util/macros.h"
+#include <cstddef>
#include <new>
#include <type_traits>
#include <utility>
@@ -321,8 +322,9 @@ public:
/// ```
template <typename E> class Result<void, E> {
private:
- using ErrorStorage =
- typename std::aligned_storage<sizeof(E), alignof(E)>::type;
+ using ErrorStorage = struct alignas(E) {
+ std::byte data[sizeof(E)];
+ };
ErrorStorage error_storage_;
bool has_value_;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]