diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h --- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h +++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h @@ -600,17 +600,15 @@ /// Convert \c this into a \c Matcher by applying dyn_cast<> to the /// argument. /// \c To must be a base class of \c T. - template Matcher dynCastTo() const LLVM_LVALUE_FUNCTION { + template Matcher dynCastTo() const & { static_assert(std::is_base_of::value, "Invalid dynCast call."); return Matcher(Implementation); } -#if LLVM_HAS_RVALUE_REFERENCE_THIS template Matcher dynCastTo() && { static_assert(std::is_base_of::value, "Invalid dynCast call."); return Matcher(std::move(Implementation)); } -#endif /// Forwards the call to the underlying MatcherInterface pointer. bool matches(const T &Node, @@ -628,13 +626,11 @@ /// /// The returned matcher keeps the same restrictions as \c this and remembers /// that it is meant to support nodes of type \c T. - operator DynTypedMatcher() const LLVM_LVALUE_FUNCTION { + operator DynTypedMatcher() const & { return Implementation; } -#if LLVM_HAS_RVALUE_REFERENCE_THIS operator DynTypedMatcher() && { return std::move(Implementation); } -#endif /// Allows the conversion of a \c Matcher to a \c /// Matcher. @@ -1361,35 +1357,31 @@ VariadicOperatorMatcher(DynTypedMatcher::VariadicOperator Op, Ps &&... Params) : Op(Op), Params(std::forward(Params)...) {} - template operator Matcher() const LLVM_LVALUE_FUNCTION { + template operator Matcher() const & { return DynTypedMatcher::constructVariadic( Op, ASTNodeKind::getFromNodeKind(), getMatchers(std::index_sequence_for())) .template unconditionalConvertTo(); } -#if LLVM_HAS_RVALUE_REFERENCE_THIS template operator Matcher() && { return DynTypedMatcher::constructVariadic( Op, ASTNodeKind::getFromNodeKind(), getMatchers(std::index_sequence_for())) .template unconditionalConvertTo(); } -#endif + private: // Helper method to unpack the tuple into a vector. template - std::vector - getMatchers(std::index_sequence) const LLVM_LVALUE_FUNCTION { + std::vector getMatchers(std::index_sequence) const & { return {Matcher(std::get(Params))...}; } -#if LLVM_HAS_RVALUE_REFERENCE_THIS template std::vector getMatchers(std::index_sequence) && { return {Matcher(std::get(std::move(Params)))...}; } -#endif const DynTypedMatcher::VariadicOperator Op; std::tuple Params; @@ -1479,15 +1471,13 @@ using ReturnTypes = ToTypes; - template operator Matcher() const LLVM_LVALUE_FUNCTION { + template operator Matcher() const & { return Matcher(new ArgumentAdapterT(InnerMatcher)); } -#if LLVM_HAS_RVALUE_REFERENCE_THIS template operator Matcher() && { return Matcher(new ArgumentAdapterT(std::move(InnerMatcher))); } -#endif private: Matcher InnerMatcher; @@ -1558,21 +1548,19 @@ TraversalWrapper(TraversalKind TK, const MatcherType &InnerMatcher) : TK(TK), InnerMatcher(InnerMatcher) {} - template operator Matcher() const LLVM_LVALUE_FUNCTION { + template operator Matcher() const & { return internal::DynTypedMatcher::constructRestrictedWrapper( new internal::TraversalMatcher(TK, InnerMatcher), ASTNodeKind::getFromNodeKind()) .template unconditionalConvertTo(); } -#if LLVM_HAS_RVALUE_REFERENCE_THIS template operator Matcher() && { return internal::DynTypedMatcher::constructRestrictedWrapper( new internal::TraversalMatcher(TK, std::move(InnerMatcher)), ASTNodeKind::getFromNodeKind()) .template unconditionalConvertTo(); } -#endif private: TraversalKind TK; @@ -1599,20 +1587,18 @@ using ReturnTypes = typename ExtractFunctionArgMeta::type; - template operator Matcher() const LLVM_LVALUE_FUNCTION { + template operator Matcher() const & { static_assert(TypeListContainsSuperOf::value, "right polymorphic conversion"); return Matcher(new_from_tuple>(Params)); } -#if LLVM_HAS_RVALUE_REFERENCE_THIS template operator Matcher() && { static_assert(TypeListContainsSuperOf::value, "right polymorphic conversion"); return Matcher( new_from_tuple>(std::move(Params))); } -#endif private: std::tuple Params; diff --git a/clang/include/clang/Basic/DirectoryEntry.h b/clang/include/clang/Basic/DirectoryEntry.h --- a/clang/include/clang/Basic/DirectoryEntry.h +++ b/clang/include/clang/Basic/DirectoryEntry.h @@ -128,20 +128,18 @@ bool hasValue() const { return MaybeRef.hasOptionalValue(); } - RefTy &getValue() LLVM_LVALUE_FUNCTION { + RefTy &getValue() & { assert(hasValue()); return MaybeRef; } - RefTy const &getValue() const LLVM_LVALUE_FUNCTION { + RefTy const &getValue() const & { assert(hasValue()); return MaybeRef; } -#if LLVM_HAS_RVALUE_REFERENCE_THIS RefTy &&getValue() && { assert(hasValue()); return std::move(MaybeRef); } -#endif template void emplace(Args &&...args) { MaybeRef = RefTy(std::forward(args)...); diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h @@ -169,7 +169,7 @@ const ProgramStateRef &getState() const { return State; } template - Optional getLocationAs() const LLVM_LVALUE_FUNCTION { + Optional getLocationAs() const & { return Location.getAs(); } diff --git a/llvm/include/llvm/ADT/Optional.h b/llvm/include/llvm/ADT/Optional.h --- a/llvm/include/llvm/ADT/Optional.h +++ b/llvm/include/llvm/ADT/Optional.h @@ -93,20 +93,18 @@ constexpr bool hasValue() const noexcept { return hasVal; } - T &getValue() LLVM_LVALUE_FUNCTION noexcept { + T &getValue() & noexcept { assert(hasVal); return value; } - constexpr T const &getValue() const LLVM_LVALUE_FUNCTION noexcept { + constexpr 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(); @@ -193,20 +191,18 @@ constexpr bool hasValue() const noexcept { return hasVal; } - T &getValue() LLVM_LVALUE_FUNCTION noexcept { + T &getValue() & noexcept { assert(hasVal); return value; } - constexpr T const &getValue() const LLVM_LVALUE_FUNCTION noexcept { + constexpr 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(); @@ -280,34 +276,32 @@ constexpr const T *getPointer() const { return &Storage.getValue(); } T *getPointer() { return &Storage.getValue(); } - constexpr const T &getValue() const LLVM_LVALUE_FUNCTION { + constexpr const T &getValue() const & { return Storage.getValue(); } - T &getValue() LLVM_LVALUE_FUNCTION { return Storage.getValue(); } + T &getValue() & { return Storage.getValue(); } constexpr explicit operator bool() const { return hasValue(); } constexpr bool hasValue() const { return Storage.hasValue(); } constexpr const T *operator->() const { return getPointer(); } T *operator->() { return getPointer(); } - constexpr const T &operator*() const LLVM_LVALUE_FUNCTION { + constexpr const T &operator*() const & { return getValue(); } - T &operator*() LLVM_LVALUE_FUNCTION { return getValue(); } + T &operator*() & { return getValue(); } - template - constexpr T getValueOr(U &&value) const LLVM_LVALUE_FUNCTION { + template constexpr T getValueOr(U &&value) const & { return hasValue() ? getValue() : std::forward(value); } /// Apply a function to the value if present; otherwise return None. template - auto map(const Function &F) const LLVM_LVALUE_FUNCTION - -> Optional { - if (*this) return F(getValue()); + auto map(const Function &F) const & -> Optional { + if (*this) + return F(getValue()); return None; } -#if LLVM_HAS_RVALUE_REFERENCE_THIS T &&getValue() && { return std::move(Storage.getValue()); } T &&operator*() && { return std::move(Storage.getValue()); } @@ -323,7 +317,6 @@ if (*this) return F(std::move(*this).getValue()); return None; } -#endif }; template llvm::hash_code hash_value(const Optional &O) { diff --git a/llvm/include/llvm/ADT/PointerIntPair.h b/llvm/include/llvm/ADT/PointerIntPair.h --- a/llvm/include/llvm/ADT/PointerIntPair.h +++ b/llvm/include/llvm/ADT/PointerIntPair.h @@ -61,19 +61,19 @@ IntType getInt() const { return (IntType)Info::getInt(Value); } - void setPointer(PointerTy PtrVal) LLVM_LVALUE_FUNCTION { + void setPointer(PointerTy PtrVal) & { Value = Info::updatePointer(Value, PtrVal); } - void setInt(IntType IntVal) LLVM_LVALUE_FUNCTION { + void setInt(IntType IntVal) & { Value = Info::updateInt(Value, static_cast(IntVal)); } - void initWithPointer(PointerTy PtrVal) LLVM_LVALUE_FUNCTION { + void initWithPointer(PointerTy PtrVal) & { Value = Info::updatePointer(0, PtrVal); } - void setPointerAndInt(PointerTy PtrVal, IntType IntVal) LLVM_LVALUE_FUNCTION { + void setPointerAndInt(PointerTy PtrVal, IntType IntVal) & { Value = Info::updateInt(Info::updatePointer(0, PtrVal), static_cast(IntVal)); } @@ -91,7 +91,7 @@ void *getOpaqueValue() const { return reinterpret_cast(Value); } - void setFromOpaqueValue(void *Val) LLVM_LVALUE_FUNCTION { + void setFromOpaqueValue(void *Val) & { Value = reinterpret_cast(Val); } diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h --- a/llvm/include/llvm/Support/Compiler.h +++ b/llvm/include/llvm/Support/Compiler.h @@ -98,24 +98,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. This appears to be -/// corrected in MSVC 2019 but not MSVC 2017. -/// FIXME: Remove LLVM_HAS_RVALUE_REFERENCE_THIS macro -#define LLVM_HAS_RVALUE_REFERENCE_THIS 1 - -/// 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/llvm/unittests/ADT/OptionalTest.cpp b/llvm/unittests/ADT/OptionalTest.cpp --- a/llvm/unittests/ADT/OptionalTest.cpp +++ b/llvm/unittests/ADT/OptionalTest.cpp @@ -578,8 +578,6 @@ Optional TestInstantiation; } -#if LLVM_HAS_RVALUE_REFERENCE_THIS - TEST(OptionalTest, MoveGetValueOr) { Optional A; @@ -597,8 +595,6 @@ 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;