@@ -69,18 +69,20 @@ class OptionalStorage {
69
69
70
70
bool hasValue () const noexcept { return hasVal; }
71
71
72
- T &getValue () & noexcept {
72
+ T &getValue () LLVM_LVALUE_FUNCTION noexcept {
73
73
assert (hasVal);
74
74
return value;
75
75
}
76
- T const &getValue () const & noexcept {
76
+ T const &getValue () const LLVM_LVALUE_FUNCTION noexcept {
77
77
assert (hasVal);
78
78
return value;
79
79
}
80
+ #if LLVM_HAS_RVALUE_REFERENCE_THIS
80
81
T &&getValue() && noexcept {
81
82
assert (hasVal);
82
83
return std::move (value);
83
84
}
85
+ #endif
84
86
85
87
template <class ... Args> void emplace (Args &&... args) {
86
88
reset ();
@@ -167,19 +169,20 @@ template <typename T> class OptionalStorage<T, true> {
167
169
168
170
bool hasValue () const noexcept { return hasVal; }
169
171
170
- T &getValue () & noexcept {
172
+ T &getValue () LLVM_LVALUE_FUNCTION noexcept {
171
173
assert (hasVal);
172
174
return value;
173
175
}
174
- T const &getValue () const & noexcept {
176
+ T const &getValue () const LLVM_LVALUE_FUNCTION noexcept {
175
177
assert (hasVal);
176
178
return value;
177
179
}
178
-
180
+ # if LLVM_HAS_RVALUE_REFERENCE_THIS
179
181
T &&getValue() && noexcept {
180
182
assert (hasVal);
181
183
return std::move (value);
182
184
}
185
+ #endif
183
186
184
187
template <class ... Args> void emplace (Args &&... args) {
185
188
reset ();
@@ -249,28 +252,30 @@ template <typename T> class Optional {
249
252
250
253
const T *getPointer () const { return &Storage.getValue (); }
251
254
T *getPointer () { return &Storage.getValue (); }
252
- const T &getValue () const & { return Storage.getValue (); }
253
- T &getValue () & { return Storage.getValue (); }
255
+ const T &getValue () const LLVM_LVALUE_FUNCTION { return Storage.getValue (); }
256
+ T &getValue () LLVM_LVALUE_FUNCTION { return Storage.getValue (); }
254
257
255
258
explicit operator bool () const { return hasValue (); }
256
259
bool hasValue () const { return Storage.hasValue (); }
257
260
const T *operator ->() const { return getPointer (); }
258
261
T *operator ->() { return getPointer (); }
259
- const T &operator *() const & { return getValue (); }
260
- T &operator *() & { return getValue (); }
262
+ const T &operator *() const LLVM_LVALUE_FUNCTION { return getValue (); }
263
+ T &operator *() LLVM_LVALUE_FUNCTION { return getValue (); }
261
264
262
265
template <typename U>
263
- constexpr T getValueOr (U &&value) const & {
266
+ constexpr T getValueOr (U &&value) const LLVM_LVALUE_FUNCTION {
264
267
return hasValue () ? getValue () : std::forward<U>(value);
265
268
}
266
269
270
+ #if LLVM_HAS_RVALUE_REFERENCE_THIS
267
271
T &&getValue() && { return std::move (Storage.getValue ()); }
268
272
T &&operator *() && { return std::move (Storage.getValue ()); }
269
273
270
274
template <typename U>
271
275
T getValueOr (U &&value) && {
272
276
return hasValue () ? std::move (getValue ()) : std::forward<U>(value);
273
277
}
278
+ #endif
274
279
};
275
280
276
281
template <typename T, typename U>
0 commit comments