From: JF Bastien Date: Wed, 14 Aug 2019 22:48:12 +0000 (+0000) Subject: Remove LVALUE / RVALUE workarounds X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6d385cd1f1228f53a084004d977465b39e7e91bb;p=llvm 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 --- diff --git a/include/llvm/ADT/Optional.h b/include/llvm/ADT/Optional.h index b45a74002e1..420f21b0d64 100644 --- a/include/llvm/ADT/Optional.h +++ b/include/llvm/ADT/Optional.h @@ -69,20 +69,18 @@ public: bool hasValue() const noexcept { return hasVal; } - T &getValue() LLVM_LVALUE_FUNCTION noexcept { + T &getValue() & noexcept { assert(hasVal); return value; } - T const &getValue() const LLVM_LVALUE_FUNCTION noexcept { + T const &getValue() const & noexcept { assert(hasVal); return value; } -#if LLVM_HAS_RVALUE_REFERENCE_THIS T &&getValue() && noexcept { assert(hasVal); return std::move(value); } -#endif template void emplace(Args &&... args) { reset(); @@ -169,20 +167,19 @@ public: bool hasValue() const noexcept { return hasVal; } - T &getValue() LLVM_LVALUE_FUNCTION noexcept { + T &getValue() & noexcept { assert(hasVal); return value; } - T const &getValue() const LLVM_LVALUE_FUNCTION noexcept { + T const &getValue() const & noexcept { assert(hasVal); return value; } -#if LLVM_HAS_RVALUE_REFERENCE_THIS + T &&getValue() && noexcept { assert(hasVal); return std::move(value); } -#endif template void emplace(Args &&... args) { reset(); @@ -252,22 +249,21 @@ public: const T *getPointer() const { return &Storage.getValue(); } T *getPointer() { return &Storage.getValue(); } - const T &getValue() const LLVM_LVALUE_FUNCTION { return Storage.getValue(); } - T &getValue() LLVM_LVALUE_FUNCTION { return Storage.getValue(); } + const T &getValue() const & { return Storage.getValue(); } + T &getValue() & { return Storage.getValue(); } explicit operator bool() const { return hasValue(); } bool hasValue() const { return Storage.hasValue(); } const T *operator->() const { return getPointer(); } T *operator->() { return getPointer(); } - const T &operator*() const LLVM_LVALUE_FUNCTION { return getValue(); } - T &operator*() LLVM_LVALUE_FUNCTION { return getValue(); } + const T &operator*() const & { return getValue(); } + T &operator*() & { return getValue(); } template - constexpr T getValueOr(U &&value) const LLVM_LVALUE_FUNCTION { + constexpr T getValueOr(U &&value) const & { return hasValue() ? getValue() : std::forward(value); } -#if LLVM_HAS_RVALUE_REFERENCE_THIS T &&getValue() && { return std::move(Storage.getValue()); } T &&operator*() && { return std::move(Storage.getValue()); } @@ -275,7 +271,6 @@ public: T getValueOr(U &&value) && { return hasValue() ? std::move(getValue()) : std::forward(value); } -#endif }; template diff --git a/include/llvm/Support/Compiler.h b/include/llvm/Support/Compiler.h index 43114ad3a43..8f54db7c826 100644 --- a/include/llvm/Support/Compiler.h +++ b/include/llvm/Support/Compiler.h @@ -83,26 +83,6 @@ #define LLVM_MSC_PREREQ(version) 0 #endif -/// Does the compiler support ref-qualifiers for *this? -/// -/// Sadly, this is separate from just rvalue reference support because GCC -/// and MSVC implemented this later than everything else. -#if __has_feature(cxx_rvalue_references) || LLVM_GNUC_PREREQ(4, 8, 1) -#define LLVM_HAS_RVALUE_REFERENCE_THIS 1 -#else -#define LLVM_HAS_RVALUE_REFERENCE_THIS 0 -#endif - -/// Expands to '&' if ref-qualifiers for *this are supported. -/// -/// This can be used to provide lvalue/rvalue overrides of member functions. -/// The rvalue override should be guarded by LLVM_HAS_RVALUE_REFERENCE_THIS -#if LLVM_HAS_RVALUE_REFERENCE_THIS -#define LLVM_LVALUE_FUNCTION & -#else -#define LLVM_LVALUE_FUNCTION -#endif - /// LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked /// into a shared library, then the class should be private to the library and /// not accessible from outside it. Can also be used to mark variables and diff --git a/unittests/ADT/OptionalTest.cpp b/unittests/ADT/OptionalTest.cpp index 1f26c101183..3b58abf57d7 100644 --- a/unittests/ADT/OptionalTest.cpp +++ b/unittests/ADT/OptionalTest.cpp @@ -382,8 +382,6 @@ TEST_F(OptionalTest, ImmovableEmplace) { EXPECT_EQ(0u, Immovable::Destructions); } -#if LLVM_HAS_RVALUE_REFERENCE_THIS - TEST_F(OptionalTest, MoveGetValueOr) { Optional A; @@ -401,8 +399,6 @@ TEST_F(OptionalTest, MoveGetValueOr) { EXPECT_EQ(2u, MoveOnly::Destructions); } -#endif // LLVM_HAS_RVALUE_REFERENCE_THIS - struct EqualTo { template static bool apply(const T &X, const U &Y) { return X == Y;