Title: [242778] trunk
- Revision
- 242778
- Author
- [email protected]
- Date
- 2019-03-11 23:04:22 -0700 (Mon, 11 Mar 2019)
Log Message
WTF::Expected should use std::addressof instead of operator&
https://bugs.webkit.org/show_bug.cgi?id=195604
Patch by Alex Christensen <[email protected]> on 2019-03-11
Reviewed by Myles Maxfield.
Source/WTF:
The latter was causing problems with types that do tricky things with constructors and operator&,
specifically UniqueRef but I made a reduced test case. When it used operator&, it would get the contained
type and call the constructor that takes a contained type instead of the move constructor.
* wtf/Expected.h:
(std::experimental::fundamentals_v3::__expected_detail::base::base):
(std::experimental::fundamentals_v3::expected::swap):
Tools:
* TestWebKitAPI/Tests/WTF/Expected.cpp:
(TestWebKitAPI::Unique::Unique):
(TestWebKitAPI::Unique::operator&):
(TestWebKitAPI::TEST):
Modified Paths
Diff
Modified: trunk/Source/WTF/ChangeLog (242777 => 242778)
--- trunk/Source/WTF/ChangeLog 2019-03-12 05:50:21 UTC (rev 242777)
+++ trunk/Source/WTF/ChangeLog 2019-03-12 06:04:22 UTC (rev 242778)
@@ -1,3 +1,18 @@
+2019-03-11 Alex Christensen <[email protected]>
+
+ WTF::Expected should use std::addressof instead of operator&
+ https://bugs.webkit.org/show_bug.cgi?id=195604
+
+ Reviewed by Myles Maxfield.
+
+ The latter was causing problems with types that do tricky things with constructors and operator&,
+ specifically UniqueRef but I made a reduced test case. When it used operator&, it would get the contained
+ type and call the constructor that takes a contained type instead of the move constructor.
+
+ * wtf/Expected.h:
+ (std::experimental::fundamentals_v3::__expected_detail::base::base):
+ (std::experimental::fundamentals_v3::expected::swap):
+
2019-03-11 Ross Kirsling <[email protected]>
Add Optional to Forward.h.
Modified: trunk/Source/WTF/wtf/Expected.h (242777 => 242778)
--- trunk/Source/WTF/wtf/Expected.h 2019-03-12 05:50:21 UTC (rev 242777)
+++ trunk/Source/WTF/wtf/Expected.h 2019-03-12 06:04:22 UTC (rev 242778)
@@ -334,17 +334,17 @@
: has(o.has)
{
if (has)
- ::new (&s.val) value_type(o.s.val);
+ ::new (std::addressof(s.val)) value_type(o.s.val);
else
- ::new (&s.err) error_type(o.s.err);
+ ::new (std::addressof(s.err)) error_type(o.s.err);
}
base(base&& o)
: has(o.has)
{
if (has)
- ::new (&s.val) value_type(std::move(o.s.val));
+ ::new (std::addressof(s.val)) value_type(std::move(o.s.val));
else
- ::new (&s.err) error_type(std::move(o.s.err));
+ ::new (std::addressof(s.err)) error_type(std::move(o.s.err));
}
~base()
{
@@ -386,13 +386,13 @@
: has(o.has)
{
if (!has)
- ::new (&s.err) error_type(o.s.err);
+ ::new (std::addressof(s.err)) error_type(o.s.err);
}
base(base&& o)
: has(o.has)
{
if (!has)
- ::new (&s.err) error_type(std::move(o.s.err));
+ ::new (std::addressof(s.err)) error_type(std::move(o.s.err));
}
~base()
{
@@ -461,16 +461,16 @@
else if (base::has && !o.has) {
error_type e(std::move(o.s.err));
__expected_detail::destroy(o.s.err);
- ::new (&o.s.val) value_type(std::move(base::s.val));
+ ::new (std::addressof(o.s.val)) value_type(std::move(base::s.val));
__expected_detail::destroy(base::s.val);
- ::new (&base::s.err) error_type(std::move(e));
+ ::new (std::addressof(base::s.err)) error_type(std::move(e));
swap(base::has, o.has);
} else if (!base::has && o.has) {
value_type v(std::move(o.s.val));
__expected_detail::destroy(o.s.val);
- ::new (&o.s.err) error_type(std::move(base::s.err));
+ ::new (std::addressof(o.s.err)) error_type(std::move(base::s.err));
__expected_detail::destroy(base::s.err);
- ::new (&base::s.val) value_type(std::move(v));
+ ::new (std::addressof(base::s.val)) value_type(std::move(v));
swap(base::has, o.has);
} else
swap(base::s.err, o.s.err);
@@ -536,10 +536,10 @@
// Do nothing.
} else if (base::has && !o.has) {
error_type e(std::move(o.s.err));
- ::new (&base::s.err) error_type(e);
+ ::new (std::addressof(base::s.err)) error_type(e);
swap(base::has, o.has);
} else if (!base::has && o.has) {
- ::new (&o.s.err) error_type(std::move(base::s.err));
+ ::new (std::addressof(o.s.err)) error_type(std::move(base::s.err));
swap(base::has, o.has);
} else
swap(base::s.err, o.s.err);
Modified: trunk/Tools/ChangeLog (242777 => 242778)
--- trunk/Tools/ChangeLog 2019-03-12 05:50:21 UTC (rev 242777)
+++ trunk/Tools/ChangeLog 2019-03-12 06:04:22 UTC (rev 242778)
@@ -1,3 +1,15 @@
+2019-03-11 Alex Christensen <[email protected]>
+
+ WTF::Expected should use std::addressof instead of operator&
+ https://bugs.webkit.org/show_bug.cgi?id=195604
+
+ Reviewed by Myles Maxfield.
+
+ * TestWebKitAPI/Tests/WTF/Expected.cpp:
+ (TestWebKitAPI::Unique::Unique):
+ (TestWebKitAPI::Unique::operator&):
+ (TestWebKitAPI::TEST):
+
2019-03-11 Ross Kirsling <[email protected]>
Add Optional to Forward.h.
Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/Expected.cpp (242777 => 242778)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/Expected.cpp 2019-03-12 05:50:21 UTC (rev 242777)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/Expected.cpp 2019-03-12 06:04:22 UTC (rev 242778)
@@ -472,4 +472,23 @@
ASSERT_STREQ("ref(a) deref(a) ", takeLogStr().c_str());
}
+class NeedsStdAddress {
+public:
+ NeedsStdAddress(NeedsStdAddress&& other)
+ : m_ptr(WTFMove(other.m_ptr)) { }
+ NeedsStdAddress(int& other)
+ : m_ptr(&other) { }
+ int* operator&() { ASSERT_NOT_REACHED(); return nullptr; }
+private:
+ std::unique_ptr<int> m_ptr;
+};
+
+TEST(WTF_Expected, Address)
+{
+ NeedsStdAddress a(*new int(3));
+ Expected<NeedsStdAddress, float> b(WTFMove(a));
+ Expected<NeedsStdAddress, float> c(WTFMove(b));
+ (void)c;
+}
+
} // namespace TestWebkitAPI
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes