Unconditionally enable lvalue function designators; NFC

We previously had to guard against older MSVC and GCC versions which had rvalue
references but not support for marking functions with ref qualifiers. However,
having bumped our minimum required version to MSVC 2017 and GCC 5.1 mean we can
unconditionally enable this feature. Rather than keeping the macro around, this
replaces use of the macro with the actual ref qualifier.
This commit is contained in:
Aaron Ballman 2020-01-22 09:53:06 -05:00
parent 0ade2abdb0
commit 968561bcdc
5 changed files with 16 additions and 49 deletions

View File

@ -34,7 +34,6 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/Compiler.h"
#include <cassert>
#include <cstdint>
#include <memory>
@ -169,7 +168,7 @@ public:
const ProgramStateRef &getState() const { return State; }
template <typename T>
Optional<T> getLocationAs() const LLVM_LVALUE_FUNCTION {
Optional<T> getLocationAs() const & {
return Location.getAs<T>();
}

View File

@ -16,7 +16,6 @@
#define LLVM_ADT_OPTIONAL_H
#include "llvm/ADT/None.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/type_traits.h"
#include <cassert>
#include <memory>
@ -69,20 +68,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 <class... Args> void emplace(Args &&... args) {
reset();
@ -169,20 +166,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 <class... Args> void emplace(Args &&... args) {
reset();
@ -252,30 +247,29 @@ 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 <typename U>
constexpr T getValueOr(U &&value) const LLVM_LVALUE_FUNCTION {
constexpr T getValueOr(U &&value) const & {
return hasValue() ? getValue() : std::forward<U>(value);
}
/// Apply a function to the value if present; otherwise return None.
template <class Function>
auto map(const Function &F) const
auto map(const Function &F) const &
-> Optional<decltype(F(getValue()))> {
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()); }
@ -291,7 +285,6 @@ public:
if (*this) return F(std::move(*this).getValue());
return None;
}
#endif
};
template <typename T, typename U>

View File

@ -13,7 +13,6 @@
#ifndef LLVM_ADT_POINTERINTPAIR_H
#define LLVM_ADT_POINTERINTPAIR_H
#include "llvm/Support/Compiler.h"
#include "llvm/Support/PointerLikeTypeTraits.h"
#include "llvm/Support/type_traits.h"
#include <cassert>
@ -60,19 +59,19 @@ public:
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<intptr_t>(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<intptr_t>(IntVal));
}
@ -90,7 +89,7 @@ public:
void *getOpaqueValue() const { return reinterpret_cast<void *>(Value); }
void setFromOpaqueValue(void *Val) LLVM_LVALUE_FUNCTION {
void setFromOpaqueValue(void *Val) & {
Value = reinterpret_cast<intptr_t>(Val);
}

View File

@ -92,26 +92,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

View File

@ -382,8 +382,6 @@ TEST_F(OptionalTest, ImmovableEmplace) {
EXPECT_EQ(0u, Immovable::Destructions);
}
#if LLVM_HAS_RVALUE_REFERENCE_THIS
TEST_F(OptionalTest, MoveGetValueOr) {
Optional<MoveOnly> A;
@ -401,8 +399,6 @@ TEST_F(OptionalTest, MoveGetValueOr) {
EXPECT_EQ(2u, MoveOnly::Destructions);
}
#endif // LLVM_HAS_RVALUE_REFERENCE_THIS
struct EqualTo {
template <typename T, typename U> static bool apply(const T &X, const U &Y) {
return X == Y;