llvm.org GIT mirror llvm / 6d385cd
Remove LVALUE / RVALUE workarounds Summary: LLVM_HAS_RVALUE_REFERENCE_THIS and LLVM_LVALUE_FUNCTION shouldn't be needed anymore because the minimum compiler versions support them. Subscribers: jkorous, dexonsmith, cfe-commits, llvm-commits, hans, thakis, chandlerc, rnk Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D66240 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@368939 91177308-0d34-0410-b5e6-96231b3b80d8 JF Bastien a month ago
3 changed file(s) with 10 addition(s) and 39 deletion(s). Raw diff Collapse all Expand all
6868
6969 bool hasValue() const noexcept { return hasVal; }
7070
71 T &getValue() LLVM_LVALUE_FUNCTION noexcept {
71 T &getValue() & noexcept {
7272 assert(hasVal);
7373 return value;
7474 }
75 T const &getValue() const LLVM_LVALUE_FUNCTION noexcept {
75 T const &getValue() const & noexcept {
7676 assert(hasVal);
7777 return value;
7878 }
79 #if LLVM_HAS_RVALUE_REFERENCE_THIS
8079 T &&getValue() && noexcept {
8180 assert(hasVal);
8281 return std::move(value);
8382 }
84 #endif
8583
8684 template void emplace(Args &&... args) {
8785 reset();
168166
169167 bool hasValue() const noexcept { return hasVal; }
170168
171 T &getValue() LLVM_LVALUE_FUNCTION noexcept {
169 T &getValue() & noexcept {
172170 assert(hasVal);
173171 return value;
174172 }
175 T const &getValue() const LLVM_LVALUE_FUNCTION noexcept {
173 T const &getValue() const & noexcept {
176174 assert(hasVal);
177175 return value;
178176 }
179 #if LLVM_HAS_RVALUE_REFERENCE_THIS
177
180178 T &&getValue() && noexcept {
181179 assert(hasVal);
182180 return std::move(value);
183181 }
184 #endif
185182
186183 template void emplace(Args &&... args) {
187184 reset();
251248
252249 const T *getPointer() const { return &Storage.getValue(); }
253250 T *getPointer() { return &Storage.getValue(); }
254 const T &getValue() const LLVM_LVALUE_FUNCTION { return Storage.getValue(); }
255 T &getValue() LLVM_LVALUE_FUNCTION { return Storage.getValue(); }
251 const T &getValue() const & { return Storage.getValue(); }
252 T &getValue() & { return Storage.getValue(); }
256253
257254 explicit operator bool() const { return hasValue(); }
258255 bool hasValue() const { return Storage.hasValue(); }
259256 const T *operator->() const { return getPointer(); }
260257 T *operator->() { return getPointer(); }
261 const T &operator*() const LLVM_LVALUE_FUNCTION { return getValue(); }
262 T &operator*() LLVM_LVALUE_FUNCTION { return getValue(); }
258 const T &operator*() const & { return getValue(); }
259 T &operator*() & { return getValue(); }
263260
264261 template
265 constexpr T getValueOr(U &&value) const LLVM_LVALUE_FUNCTION {
262 constexpr T getValueOr(U &&value) const & {
266263 return hasValue() ? getValue() : std::forward(value);
267264 }
268265
269 #if LLVM_HAS_RVALUE_REFERENCE_THIS
270266 T &&getValue() && { return std::move(Storage.getValue()); }
271267 T &&operator*() && { return std::move(Storage.getValue()); }
272268
274270 T getValueOr(U &&value) && {
275271 return hasValue() ? std::move(getValue()) : std::forward(value);
276272 }
277 #endif
278273 };
279274
280275 template
8080
8181 #else
8282 #define LLVM_MSC_PREREQ(version) 0
83 #endif
84
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
10383 #endif
10484
10585 /// LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked
381381 EXPECT_EQ(0u, Immovable::Destructions);
382382 }
383383
384 #if LLVM_HAS_RVALUE_REFERENCE_THIS
385
386384 TEST_F(OptionalTest, MoveGetValueOr) {
387385 Optional A;
388386
399397 EXPECT_EQ(0u, MoveOnly::MoveAssignments);
400398 EXPECT_EQ(2u, MoveOnly::Destructions);
401399 }
402
403 #endif // LLVM_HAS_RVALUE_REFERENCE_THIS
404400
405401 struct EqualTo {
406402 template static bool apply(const T &X, const U &Y) {