llvm.org GIT mirror llvm / 4ed5b9a
Revert rL368939 "Remove LVALUE / RVALUE workarounds" This reverts commit cad8356d699b36c73abb267f65db575ddacbd652. To unbreak Windows bots git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@368985 91177308-0d34-0410-b5e6-96231b3b80d8 Russell Gallop a month ago
3 changed file(s) with 39 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
6868
6969 bool hasValue() const noexcept { return hasVal; }
7070
71 T &getValue() & noexcept {
71 T &getValue() LLVM_LVALUE_FUNCTION noexcept {
7272 assert(hasVal);
7373 return value;
7474 }
75 T const &getValue() const & noexcept {
75 T const &getValue() const LLVM_LVALUE_FUNCTION noexcept {
7676 assert(hasVal);
7777 return value;
7878 }
79 #if LLVM_HAS_RVALUE_REFERENCE_THIS
7980 T &&getValue() && noexcept {
8081 assert(hasVal);
8182 return std::move(value);
8283 }
84 #endif
8385
8486 template void emplace(Args &&... args) {
8587 reset();
166168
167169 bool hasValue() const noexcept { return hasVal; }
168170
169 T &getValue() & noexcept {
171 T &getValue() LLVM_LVALUE_FUNCTION noexcept {
170172 assert(hasVal);
171173 return value;
172174 }
173 T const &getValue() const & noexcept {
175 T const &getValue() const LLVM_LVALUE_FUNCTION noexcept {
174176 assert(hasVal);
175177 return value;
176178 }
177
179 #if LLVM_HAS_RVALUE_REFERENCE_THIS
178180 T &&getValue() && noexcept {
179181 assert(hasVal);
180182 return std::move(value);
181183 }
184 #endif
182185
183186 template void emplace(Args &&... args) {
184187 reset();
248251
249252 const T *getPointer() const { return &Storage.getValue(); }
250253 T *getPointer() { return &Storage.getValue(); }
251 const T &getValue() const & { return Storage.getValue(); }
252 T &getValue() & { return Storage.getValue(); }
254 const T &getValue() const LLVM_LVALUE_FUNCTION { return Storage.getValue(); }
255 T &getValue() LLVM_LVALUE_FUNCTION { return Storage.getValue(); }
253256
254257 explicit operator bool() const { return hasValue(); }
255258 bool hasValue() const { return Storage.hasValue(); }
256259 const T *operator->() const { return getPointer(); }
257260 T *operator->() { return getPointer(); }
258 const T &operator*() const & { return getValue(); }
259 T &operator*() & { return getValue(); }
261 const T &operator*() const LLVM_LVALUE_FUNCTION { return getValue(); }
262 T &operator*() LLVM_LVALUE_FUNCTION { return getValue(); }
260263
261264 template
262 constexpr T getValueOr(U &&value) const & {
265 constexpr T getValueOr(U &&value) const LLVM_LVALUE_FUNCTION {
263266 return hasValue() ? getValue() : std::forward(value);
264267 }
265268
269 #if LLVM_HAS_RVALUE_REFERENCE_THIS
266270 T &&getValue() && { return std::move(Storage.getValue()); }
267271 T &&operator*() && { return std::move(Storage.getValue()); }
268272
270274 T getValueOr(U &&value) && {
271275 return hasValue() ? std::move(getValue()) : std::forward(value);
272276 }
277 #endif
273278 };
274279
275280 template
8282 #define LLVM_MSC_PREREQ(version) 0
8383 #endif
8484
85 /// Does the compiler support ref-qualifiers for *this?
86 ///
87 /// Sadly, this is separate from just rvalue reference support because GCC
88 /// and MSVC implemented this later than everything else.
89 #if __has_feature(cxx_rvalue_references) || LLVM_GNUC_PREREQ(4, 8, 1)
90 #define LLVM_HAS_RVALUE_REFERENCE_THIS 1
91 #else
92 #define LLVM_HAS_RVALUE_REFERENCE_THIS 0
93 #endif
94
95 /// Expands to '&' if ref-qualifiers for *this are supported.
96 ///
97 /// This can be used to provide lvalue/rvalue overrides of member functions.
98 /// The rvalue override should be guarded by LLVM_HAS_RVALUE_REFERENCE_THIS
99 #if LLVM_HAS_RVALUE_REFERENCE_THIS
100 #define LLVM_LVALUE_FUNCTION &
101 #else
102 #define LLVM_LVALUE_FUNCTION
103 #endif
104
85105 /// LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked
86106 /// into a shared library, then the class should be private to the library and
87107 /// not accessible from outside it. Can also be used to mark variables and
381381 EXPECT_EQ(0u, Immovable::Destructions);
382382 }
383383
384 #if LLVM_HAS_RVALUE_REFERENCE_THIS
385
384386 TEST_F(OptionalTest, MoveGetValueOr) {
385387 Optional A;
386388
397399 EXPECT_EQ(0u, MoveOnly::MoveAssignments);
398400 EXPECT_EQ(2u, MoveOnly::Destructions);
399401 }
402
403 #endif // LLVM_HAS_RVALUE_REFERENCE_THIS
400404
401405 struct EqualTo {
402406 template static bool apply(const T &X, const U &Y) {