diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h index ab7a445dbcd49a..5648c716c539ef 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h +++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h @@ -600,17 +600,15 @@ class Matcher { /// 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,9 @@ class Matcher { /// /// 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 { - return Implementation; - } + 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 +1355,31 @@ template class VariadicOperatorMatcher { 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 +1469,13 @@ class ArgumentAdaptingMatcherFuncAdaptor { 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 +1546,19 @@ template class TraversalWrapper { 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 +1585,18 @@ class PolymorphicMatcher { 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 index ac8e790230fcc9..21565621b80fc1 100644 --- a/clang/include/clang/Basic/DirectoryEntry.h +++ b/clang/include/clang/Basic/DirectoryEntry.h @@ -128,20 +128,18 @@ template class MapEntryOptionalStorage { 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 index e87772c04b9be1..faabd48574bd20 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h @@ -161,15 +161,13 @@ class ExplodedNode : public llvm::FoldingSetNode { return getLocationContext()->getParentMap(); } - template - T &getAnalysis() const { + template T &getAnalysis() const { return *getLocationContext()->getAnalysis(); } const ProgramStateRef &getState() const { return State; } - template - Optional getLocationAs() const LLVM_LVALUE_FUNCTION { + template Optional getLocationAs() const & { return Location.getAs(); } diff --git a/llvm/include/llvm/ADT/Optional.h b/llvm/include/llvm/ADT/Optional.h index e047b0fc6514f9..f4608140a974f5 100644 --- a/llvm/include/llvm/ADT/Optional.h +++ b/llvm/include/llvm/ADT/Optional.h @@ -81,7 +81,7 @@ class OptionalStorage { } template - constexpr explicit OptionalStorage(in_place_t, Args &&... args) + constexpr explicit OptionalStorage(in_place_t, Args &&...args) : value(std::forward(args)...), hasVal(true) {} void reset() noexcept { @@ -93,22 +93,20 @@ class OptionalStorage { 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 { + T &&getValue() &&noexcept { assert(hasVal); return std::move(value); } -#endif - template void emplace(Args &&... args) { + template void emplace(Args &&...args) { reset(); ::new ((void *)std::addressof(value)) T(std::forward(args)...); hasVal = true; @@ -193,22 +191,20 @@ template class OptionalStorage { 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 { + T &&getValue() &&noexcept { assert(hasVal); return std::move(value); } -#endif - template void emplace(Args &&... args) { + template void emplace(Args &&...args) { reset(); ::new ((void *)std::addressof(value)) T(std::forward(args)...); hasVal = true; @@ -280,50 +276,43 @@ template class Optional { constexpr const T *getPointer() const { return &Storage.getValue(); } T *getPointer() { return &Storage.getValue(); } - constexpr const T &getValue() const LLVM_LVALUE_FUNCTION { - return Storage.getValue(); - } - T &getValue() LLVM_LVALUE_FUNCTION { return Storage.getValue(); } + constexpr const T &getValue() const & { 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 { - return getValue(); - } - T &operator*() LLVM_LVALUE_FUNCTION { return getValue(); } + constexpr const T &operator*() const & { 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()); } - template - T getValueOr(U &&value) && { + template T getValueOr(U &&value) && { return hasValue() ? std::move(getValue()) : std::forward(value); } /// Apply a function to the value if present; otherwise return None. template - auto map(const Function &F) && - -> Optional { - if (*this) return F(std::move(*this).getValue()); + auto map(const Function &F) + && -> Optional { + 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 index b7ddf8855605d2..7d10b2a6dd149f 100644 --- a/llvm/include/llvm/ADT/PointerIntPair.h +++ b/llvm/include/llvm/ADT/PointerIntPair.h @@ -61,19 +61,19 @@ class PointerIntPair { 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 @@ class PointerIntPair { 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 index 1f044813bd74aa..63f49b3af8ff46 100644 --- a/llvm/include/llvm/Support/Compiler.h +++ b/llvm/include/llvm/Support/Compiler.h @@ -102,24 +102,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 index b664792f2dfb97..06283f477e5565 100644 --- a/llvm/unittests/ADT/OptionalTest.cpp +++ b/llvm/unittests/ADT/OptionalTest.cpp @@ -578,8 +578,6 @@ TEST(OptionalTest, DeletedCopyStringMap) { Optional TestInstantiation; } -#if LLVM_HAS_RVALUE_REFERENCE_THIS - TEST(OptionalTest, MoveGetValueOr) { Optional A; @@ -597,8 +595,6 @@ TEST(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;