[llvm-commits] [llvm] r168963 - in /llvm/trunk/include/llvm: ADT/Optional.h Support/Compiler.h

Jordan Rose jordan_rose at apple.com
Thu Nov 29 16:38:53 PST 2012


Author: jrose
Date: Thu Nov 29 18:38:53 2012
New Revision: 168963

URL: http://llvm.org/viewvc/llvm-project?rev=168963&view=rev
Log:
Add a new C++11 compatibility macro, LLVM_LVALUE_FUNCTION.

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.

Modified:
    llvm/trunk/include/llvm/ADT/Optional.h
    llvm/trunk/include/llvm/Support/Compiler.h

Modified: llvm/trunk/include/llvm/ADT/Optional.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/Optional.h?rev=168963&r1=168962&r2=168963&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/Optional.h (original)
+++ llvm/trunk/include/llvm/ADT/Optional.h Thu Nov 29 18:38:53 2012
@@ -48,12 +48,17 @@
   }
   
   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;

Modified: llvm/trunk/include/llvm/Support/Compiler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Compiler.h?rev=168963&r1=168962&r2=168963&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Compiler.h (original)
+++ llvm/trunk/include/llvm/Support/Compiler.h Thu Nov 29 18:38:53 2012
@@ -38,6 +38,16 @@
 #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.





More information about the llvm-commits mailing list