Skip to content

Commit f9ad934

Browse files
kedartalgraebm
andauthored
[Aws::Crt::Optional] use alignas instead of std::aligned_storage (#462)
std::aligned_storage is deprecated in c++23. Co-authored-by: Michael Graeb <[email protected]>
1 parent 7ff9e03 commit f9ad934

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

include/aws/crt/Optional.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ namespace Aws
1919
Optional() : m_value(nullptr) {}
2020
Optional(const T &val)
2121
{
22-
new (&m_storage) T(val);
23-
m_value = reinterpret_cast<T *>(&m_storage);
22+
new (m_storage) T(val);
23+
m_value = reinterpret_cast<T *>(m_storage);
2424
}
2525

2626
Optional(T &&val)
2727
{
28-
new (&m_storage) T(std::forward<T>(val));
29-
m_value = reinterpret_cast<T *>(&m_storage);
28+
new (m_storage) T(std::forward<T>(val));
29+
m_value = reinterpret_cast<T *>(m_storage);
3030
}
3131

3232
~Optional()
@@ -45,8 +45,8 @@ namespace Aws
4545
return *this;
4646
}
4747

48-
new (&m_storage) T(std::forward<U>(u));
49-
m_value = reinterpret_cast<T *>(&m_storage);
48+
new (m_storage) T(std::forward<U>(u));
49+
m_value = reinterpret_cast<T *>(m_storage);
5050

5151
return *this;
5252
}
@@ -55,8 +55,8 @@ namespace Aws
5555
{
5656
if (other.m_value)
5757
{
58-
new (&m_storage) T(*other.m_value);
59-
m_value = reinterpret_cast<T *>(&m_storage);
58+
new (m_storage) T(*other.m_value);
59+
m_value = reinterpret_cast<T *>(m_storage);
6060
}
6161
else
6262
{
@@ -68,8 +68,8 @@ namespace Aws
6868
{
6969
if (other.m_value)
7070
{
71-
new (&m_storage) T(std::forward<T>(*other.m_value));
72-
m_value = reinterpret_cast<T *>(&m_storage);
71+
new (m_storage) T(std::forward<T>(*other.m_value));
72+
m_value = reinterpret_cast<T *>(m_storage);
7373
}
7474
else
7575
{
@@ -101,8 +101,8 @@ namespace Aws
101101

102102
if (other.m_value)
103103
{
104-
new (&m_storage) T(*other.m_value);
105-
m_value = reinterpret_cast<T *>(&m_storage);
104+
new (m_storage) T(*other.m_value);
105+
m_value = reinterpret_cast<T *>(m_storage);
106106
}
107107

108108
return *this;
@@ -132,8 +132,8 @@ namespace Aws
132132

133133
if (other.m_value)
134134
{
135-
new (&m_storage) T(*other.m_value);
136-
m_value = reinterpret_cast<T *>(&m_storage);
135+
new (m_storage) T(*other.m_value);
136+
m_value = reinterpret_cast<T *>(m_storage);
137137
}
138138

139139
return *this;
@@ -163,8 +163,8 @@ namespace Aws
163163

164164
if (other.m_value)
165165
{
166-
new (&m_storage) T(std::forward<U>(*other.m_value));
167-
m_value = reinterpret_cast<T *>(&m_storage);
166+
new (m_storage) T(std::forward<U>(*other.m_value));
167+
m_value = reinterpret_cast<T *>(m_storage);
168168
}
169169

170170
return *this;
@@ -196,7 +196,7 @@ namespace Aws
196196
}
197197

198198
private:
199-
typename std::aligned_storage<sizeof(T)>::type m_storage;
199+
alignas(T) char m_storage[sizeof(T)];
200200
T *m_value;
201201
};
202202
} // namespace Crt

0 commit comments

Comments
 (0)