Skip to content

Commit 968561b

Browse files
committed
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.
1 parent 0ade2ab commit 968561b

File tree

5 files changed

+16
-49
lines changed

5 files changed

+16
-49
lines changed

clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include "llvm/ADT/STLExtras.h"
3535
#include "llvm/ADT/SetVector.h"
3636
#include "llvm/Support/Allocator.h"
37-
#include "llvm/Support/Compiler.h"
3837
#include <cassert>
3938
#include <cstdint>
4039
#include <memory>
@@ -169,7 +168,7 @@ class ExplodedNode : public llvm::FoldingSetNode {
169168
const ProgramStateRef &getState() const { return State; }
170169

171170
template <typename T>
172-
Optional<T> getLocationAs() const LLVM_LVALUE_FUNCTION {
171+
Optional<T> getLocationAs() const & {
173172
return Location.getAs<T>();
174173
}
175174

llvm/include/llvm/ADT/Optional.h

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#define LLVM_ADT_OPTIONAL_H
1717

1818
#include "llvm/ADT/None.h"
19-
#include "llvm/Support/Compiler.h"
2019
#include "llvm/Support/type_traits.h"
2120
#include <cassert>
2221
#include <memory>
@@ -69,20 +68,18 @@ class OptionalStorage {
6968

7069
bool hasValue() const noexcept { return hasVal; }
7170

72-
T &getValue() LLVM_LVALUE_FUNCTION noexcept {
71+
T &getValue() & noexcept {
7372
assert(hasVal);
7473
return value;
7574
}
76-
T const &getValue() const LLVM_LVALUE_FUNCTION noexcept {
75+
T const &getValue() const & noexcept {
7776
assert(hasVal);
7877
return value;
7978
}
80-
#if LLVM_HAS_RVALUE_REFERENCE_THIS
8179
T &&getValue() && noexcept {
8280
assert(hasVal);
8381
return std::move(value);
8482
}
85-
#endif
8683

8784
template <class... Args> void emplace(Args &&... args) {
8885
reset();
@@ -169,20 +166,18 @@ template <typename T> class OptionalStorage<T, true> {
169166

170167
bool hasValue() const noexcept { return hasVal; }
171168

172-
T &getValue() LLVM_LVALUE_FUNCTION noexcept {
169+
T &getValue() & noexcept {
173170
assert(hasVal);
174171
return value;
175172
}
176-
T const &getValue() const LLVM_LVALUE_FUNCTION noexcept {
173+
T const &getValue() const & noexcept {
177174
assert(hasVal);
178175
return value;
179176
}
180-
#if LLVM_HAS_RVALUE_REFERENCE_THIS
181177
T &&getValue() && noexcept {
182178
assert(hasVal);
183179
return std::move(value);
184180
}
185-
#endif
186181

187182
template <class... Args> void emplace(Args &&... args) {
188183
reset();
@@ -252,30 +247,29 @@ template <typename T> class Optional {
252247

253248
const T *getPointer() const { return &Storage.getValue(); }
254249
T *getPointer() { return &Storage.getValue(); }
255-
const T &getValue() const LLVM_LVALUE_FUNCTION { return Storage.getValue(); }
256-
T &getValue() LLVM_LVALUE_FUNCTION { return Storage.getValue(); }
250+
const T &getValue() const & { return Storage.getValue(); }
251+
T &getValue() & { return Storage.getValue(); }
257252

258253
explicit operator bool() const { return hasValue(); }
259254
bool hasValue() const { return Storage.hasValue(); }
260255
const T *operator->() const { return getPointer(); }
261256
T *operator->() { return getPointer(); }
262-
const T &operator*() const LLVM_LVALUE_FUNCTION { return getValue(); }
263-
T &operator*() LLVM_LVALUE_FUNCTION { return getValue(); }
257+
const T &operator*() const & { return getValue(); }
258+
T &operator*() & { return getValue(); }
264259

265260
template <typename U>
266-
constexpr T getValueOr(U &&value) const LLVM_LVALUE_FUNCTION {
261+
constexpr T getValueOr(U &&value) const & {
267262
return hasValue() ? getValue() : std::forward<U>(value);
268263
}
269264

270265
/// Apply a function to the value if present; otherwise return None.
271266
template <class Function>
272-
auto map(const Function &F) const
267+
auto map(const Function &F) const &
273268
-> Optional<decltype(F(getValue()))> {
274269
if (*this) return F(getValue());
275270
return None;
276271
}
277272

278-
#if LLVM_HAS_RVALUE_REFERENCE_THIS
279273
T &&getValue() && { return std::move(Storage.getValue()); }
280274
T &&operator*() && { return std::move(Storage.getValue()); }
281275

@@ -291,7 +285,6 @@ template <typename T> class Optional {
291285
if (*this) return F(std::move(*this).getValue());
292286
return None;
293287
}
294-
#endif
295288
};
296289

297290
template <typename T, typename U>

llvm/include/llvm/ADT/PointerIntPair.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#ifndef LLVM_ADT_POINTERINTPAIR_H
1414
#define LLVM_ADT_POINTERINTPAIR_H
1515

16-
#include "llvm/Support/Compiler.h"
1716
#include "llvm/Support/PointerLikeTypeTraits.h"
1817
#include "llvm/Support/type_traits.h"
1918
#include <cassert>
@@ -60,19 +59,19 @@ class PointerIntPair {
6059

6160
IntType getInt() const { return (IntType)Info::getInt(Value); }
6261

63-
void setPointer(PointerTy PtrVal) LLVM_LVALUE_FUNCTION {
62+
void setPointer(PointerTy PtrVal) & {
6463
Value = Info::updatePointer(Value, PtrVal);
6564
}
6665

67-
void setInt(IntType IntVal) LLVM_LVALUE_FUNCTION {
66+
void setInt(IntType IntVal) & {
6867
Value = Info::updateInt(Value, static_cast<intptr_t>(IntVal));
6968
}
7069

71-
void initWithPointer(PointerTy PtrVal) LLVM_LVALUE_FUNCTION {
70+
void initWithPointer(PointerTy PtrVal) & {
7271
Value = Info::updatePointer(0, PtrVal);
7372
}
7473

75-
void setPointerAndInt(PointerTy PtrVal, IntType IntVal) LLVM_LVALUE_FUNCTION {
74+
void setPointerAndInt(PointerTy PtrVal, IntType IntVal) & {
7675
Value = Info::updateInt(Info::updatePointer(0, PtrVal),
7776
static_cast<intptr_t>(IntVal));
7877
}
@@ -90,7 +89,7 @@ class PointerIntPair {
9089

9190
void *getOpaqueValue() const { return reinterpret_cast<void *>(Value); }
9291

93-
void setFromOpaqueValue(void *Val) LLVM_LVALUE_FUNCTION {
92+
void setFromOpaqueValue(void *Val) & {
9493
Value = reinterpret_cast<intptr_t>(Val);
9594
}
9695

llvm/include/llvm/Support/Compiler.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,26 +92,6 @@
9292
#define LLVM_MSC_PREREQ(version) 0
9393
#endif
9494

95-
/// Does the compiler support ref-qualifiers for *this?
96-
///
97-
/// Sadly, this is separate from just rvalue reference support because GCC
98-
/// and MSVC implemented this later than everything else.
99-
#if __has_feature(cxx_rvalue_references) || LLVM_GNUC_PREREQ(4, 8, 1)
100-
#define LLVM_HAS_RVALUE_REFERENCE_THIS 1
101-
#else
102-
#define LLVM_HAS_RVALUE_REFERENCE_THIS 0
103-
#endif
104-
105-
/// Expands to '&' if ref-qualifiers for *this are supported.
106-
///
107-
/// This can be used to provide lvalue/rvalue overrides of member functions.
108-
/// The rvalue override should be guarded by LLVM_HAS_RVALUE_REFERENCE_THIS
109-
#if LLVM_HAS_RVALUE_REFERENCE_THIS
110-
#define LLVM_LVALUE_FUNCTION &
111-
#else
112-
#define LLVM_LVALUE_FUNCTION
113-
#endif
114-
11595
/// LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked
11696
/// into a shared library, then the class should be private to the library and
11797
/// not accessible from outside it. Can also be used to mark variables and

llvm/unittests/ADT/OptionalTest.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,6 @@ TEST_F(OptionalTest, ImmovableEmplace) {
382382
EXPECT_EQ(0u, Immovable::Destructions);
383383
}
384384

385-
#if LLVM_HAS_RVALUE_REFERENCE_THIS
386-
387385
TEST_F(OptionalTest, MoveGetValueOr) {
388386
Optional<MoveOnly> A;
389387

@@ -401,8 +399,6 @@ TEST_F(OptionalTest, MoveGetValueOr) {
401399
EXPECT_EQ(2u, MoveOnly::Destructions);
402400
}
403401

404-
#endif // LLVM_HAS_RVALUE_REFERENCE_THIS
405-
406402
struct EqualTo {
407403
template <typename T, typename U> static bool apply(const T &X, const U &Y) {
408404
return X == Y;

0 commit comments

Comments
 (0)