[clang] dfe9f13 - Revert "Unconditionally enable lvalue function designators; NFC"

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 22 09:40:50 PST 2020


Author: Aaron Ballman
Date: 2020-01-22T12:40:39-05:00
New Revision: dfe9f130e07c929d21f8122272077495de531a38

URL: https://github.com/llvm/llvm-project/commit/dfe9f130e07c929d21f8122272077495de531a38
DIFF: https://github.com/llvm/llvm-project/commit/dfe9f130e07c929d21f8122272077495de531a38.diff

LOG: Revert "Unconditionally enable lvalue function designators; NFC"

This reverts commit 968561bcdc34c7d74482fe3bb69a045abf08d2c1

Added: 
    

Modified: 
    clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
    llvm/include/llvm/ADT/Optional.h
    llvm/include/llvm/ADT/PointerIntPair.h
    llvm/include/llvm/Support/Compiler.h
    llvm/unittests/ADT/OptionalTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
index e808423cb1f5..e87772c04b9b 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
@@ -34,6 +34,7 @@
 #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>
@@ -168,7 +169,7 @@ class ExplodedNode : public llvm::FoldingSetNode {
   const ProgramStateRef &getState() const { return State; }
 
   template <typename T>
-  Optional<T> getLocationAs() const & {
+  Optional<T> getLocationAs() const LLVM_LVALUE_FUNCTION {
     return Location.getAs<T>();
   }
 

diff  --git a/llvm/include/llvm/ADT/Optional.h b/llvm/include/llvm/ADT/Optional.h
index 95363439aa7b..c84f9aa8b342 100644
--- a/llvm/include/llvm/ADT/Optional.h
+++ b/llvm/include/llvm/ADT/Optional.h
@@ -16,6 +16,7 @@
 #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>
@@ -68,18 +69,20 @@ class OptionalStorage {
 
   bool hasValue() const noexcept { return hasVal; }
 
-  T &getValue() & noexcept {
+  T &getValue() LLVM_LVALUE_FUNCTION noexcept {
     assert(hasVal);
     return value;
   }
-  T const &getValue() const & noexcept {
+  T const &getValue() const LLVM_LVALUE_FUNCTION 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();
@@ -166,18 +169,20 @@ template <typename T> class OptionalStorage<T, true> {
 
   bool hasValue() const noexcept { return hasVal; }
 
-  T &getValue() & noexcept {
+  T &getValue() LLVM_LVALUE_FUNCTION noexcept {
     assert(hasVal);
     return value;
   }
-  T const &getValue() const & noexcept {
+  T const &getValue() const LLVM_LVALUE_FUNCTION 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();
@@ -247,29 +252,30 @@ template <typename T> class Optional {
 
   const T *getPointer() const { return &Storage.getValue(); }
   T *getPointer() { return &Storage.getValue(); }
-  const T &getValue() const & { return Storage.getValue(); }
-  T &getValue() & { return Storage.getValue(); }
+  const T &getValue() const LLVM_LVALUE_FUNCTION { return Storage.getValue(); }
+  T &getValue() LLVM_LVALUE_FUNCTION { 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 & { return getValue(); }
-  T &operator*() & { return getValue(); }
+  const T &operator*() const LLVM_LVALUE_FUNCTION { return getValue(); }
+  T &operator*() LLVM_LVALUE_FUNCTION { return getValue(); }
 
   template <typename U>
-  constexpr T getValueOr(U &&value) const & {
+  constexpr T getValueOr(U &&value) const LLVM_LVALUE_FUNCTION {
     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()); }
 
@@ -285,6 +291,7 @@ template <typename T> class Optional {
     if (*this) return F(std::move(*this).getValue());
     return None;
   }
+#endif
 };
 
 template <typename T, typename U>

diff  --git a/llvm/include/llvm/ADT/PointerIntPair.h b/llvm/include/llvm/ADT/PointerIntPair.h
index 8222441fda4d..bcd7941798f2 100644
--- a/llvm/include/llvm/ADT/PointerIntPair.h
+++ b/llvm/include/llvm/ADT/PointerIntPair.h
@@ -13,6 +13,7 @@
 #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>
@@ -59,19 +60,19 @@ class PointerIntPair {
 
   IntType getInt() const { return (IntType)Info::getInt(Value); }
 
-  void setPointer(PointerTy PtrVal) & {
+  void setPointer(PointerTy PtrVal) LLVM_LVALUE_FUNCTION {
     Value = Info::updatePointer(Value, PtrVal);
   }
 
-  void setInt(IntType IntVal) & {
+  void setInt(IntType IntVal) LLVM_LVALUE_FUNCTION {
     Value = Info::updateInt(Value, static_cast<intptr_t>(IntVal));
   }
 
-  void initWithPointer(PointerTy PtrVal) & {
+  void initWithPointer(PointerTy PtrVal) LLVM_LVALUE_FUNCTION {
     Value = Info::updatePointer(0, PtrVal);
   }
 
-  void setPointerAndInt(PointerTy PtrVal, IntType IntVal) & {
+  void setPointerAndInt(PointerTy PtrVal, IntType IntVal) LLVM_LVALUE_FUNCTION {
     Value = Info::updateInt(Info::updatePointer(0, PtrVal),
                             static_cast<intptr_t>(IntVal));
   }
@@ -89,7 +90,7 @@ class PointerIntPair {
 
   void *getOpaqueValue() const { return reinterpret_cast<void *>(Value); }
 
-  void setFromOpaqueValue(void *Val) & {
+  void setFromOpaqueValue(void *Val) LLVM_LVALUE_FUNCTION {
     Value = reinterpret_cast<intptr_t>(Val);
   }
 

diff  --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
index 2ed4bb7bf843..6f6f65cad6f5 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -92,6 +92,26 @@
 #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/llvm/unittests/ADT/OptionalTest.cpp b/llvm/unittests/ADT/OptionalTest.cpp
index 3b58abf57d72..1f26c101183a 100644
--- a/llvm/unittests/ADT/OptionalTest.cpp
+++ b/llvm/unittests/ADT/OptionalTest.cpp
@@ -382,6 +382,8 @@ TEST_F(OptionalTest, ImmovableEmplace) {
   EXPECT_EQ(0u, Immovable::Destructions);
 }
 
+#if LLVM_HAS_RVALUE_REFERENCE_THIS
+
 TEST_F(OptionalTest, MoveGetValueOr) {
   Optional<MoveOnly> A;
 
@@ -399,6 +401,8 @@ 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;


        


More information about the cfe-commits mailing list