Add a new C++11 compatibility macro, LLVM_LVALUE_FUNCTION.
authorJordan Rose <jordan_rose@apple.com>
Fri, 30 Nov 2012 00:38:53 +0000 (00:38 +0000)
committerJordan Rose <jordan_rose@apple.com>
Fri, 30 Nov 2012 00:38:53 +0000 (00:38 +0000)
This expands to '&', and is intended to be used when an /optional/ rvalue
override is available.

Before:
  void foo() const { ... }

After:
  void foo() const LLVM_LVALUE_FUNCTION { ... }
  void foo() && { ... }

This is used to allow moving the contents of an Optional.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168963 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/Optional.h
include/llvm/Support/Compiler.h

index f43aeb1bc4d9dadff7a9527838a934e261d742e4..23100ab1b7af939be66a2397676f0739b56bf714 100644 (file)
@@ -48,12 +48,17 @@ public:
   }
   
   const T* getPointer() const { assert(hasVal); return &x; }
-  const T& getValue() const { assert(hasVal); return x; }
+  const T& getValue() const LLVM_LVALUE_FUNCTION { assert(hasVal); return x; }
 
   operator bool() const { return hasVal; }
   bool hasValue() const { return hasVal; }
   const T* operator->() const { return getPointer(); }
-  const T& operator*() const { assert(hasVal); return x; }
+  const T& operator*() const LLVM_LVALUE_FUNCTION { assert(hasVal); return x; }
+
+#if LLVM_USE_RVALUE_REFERENCES
+  T&& getValue() && { assert(hasVal); return std::move(x); }
+  T&& operator*() && { assert(hasVal); return std::move(x); } 
+#endif
 };
 
 template<typename T> struct simplify_type;
index 5acc7160abbd74fadd62ac0e38f829aaa0619b7d..7d9785cdae59b5537ca178a277eea02464bb3e49 100644 (file)
 #define llvm_move(value) (value)
 #endif
 
+/// Expands to '&' if r-value references are supported.
+///
+/// This can be used to provide l-value/r-value overrides of member functions.
+/// The r-value override should be guarded by LLVM_USE_RVALUE_REFERENCES
+#if LLVM_USE_RVALUE_REFERENCES
+#define LLVM_LVALUE_FUNCTION &
+#else
+#define LLVM_LVALUE_FUNCTION
+#endif
+
 /// LLVM_DELETED_FUNCTION - Expands to = delete if the compiler supports it.
 /// Use to mark functions as uncallable. Member functions with this should
 /// be declared private so that some behavior is kept in C++03 mode.