Skip to content

Commit 10f6195

Browse files
committed
[Evaluator] Fix an egregious bug in move construction/assignment of AnyRequest
The default move constructor and move assignment operator of AnyRequest would leave the source object in an odd state that’s destructible but does not maintain the invariant that all “normal” states store a real instance. This state breaks DenseMap, which assumes that a moved-from object is still washable.
1 parent 7d01863 commit 10f6195

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

include/swift/AST/AnyRequest.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,20 @@ class AnyRequest {
136136

137137
public:
138138
AnyRequest(const AnyRequest &other) = default;
139-
AnyRequest(AnyRequest &&other) = default;
140139
AnyRequest &operator=(const AnyRequest &other) = default;
141-
AnyRequest &operator=(AnyRequest &&other) = default;
140+
141+
AnyRequest(AnyRequest &&other)
142+
: storageKind(other.storageKind), stored(std::move(other.stored)) {
143+
other.storageKind = StorageKind::Empty;
144+
}
145+
146+
AnyRequest &operator=(AnyRequest &&other) {
147+
storageKind = other.storageKind;
148+
stored = std::move(other.stored);
149+
other.storageKind = StorageKind::Empty;
150+
other.stored = nullptr;
151+
return *this;
152+
}
142153

143154
AnyRequest(AnyRequest &other)
144155
: storageKind(other.storageKind), stored(other.stored) { }

0 commit comments

Comments
 (0)