diff -r 01c4bca2bff5 src/lib/StdBuf.h
--- a/src/lib/StdBuf.h	Wed Mar 14 23:28:44 2012 +0100
+++ b/src/lib/StdBuf.h	Thu Mar 15 17:38:43 2012 +0000
@@ -42,6 +42,43 @@
 #include <crtdbg.h>
 #endif
 
+// * Dealing with references
+//
+// The magic here is that we want to be able to do "move
+// constructors". To be more specific, we want to "take" ownership of
+// buffers from temporary buffer objects. As these are often seen as
+// constant by the compiler, this is tricky and unfortunately pretty
+// fragile. Hopefully one of these two variants will work for
+// every important compiler out there...
+#ifdef HAVE_RVALUE_REF
+
+// Variant 1: Use the rvalue references from C++0x
+#define StdBufRef StdBuf RREF
+#define StdStrBufRef StdStrBuf RREF
+#define moveRef(r) std::move(r)
+#define mkRef(r)   r
+#define unRef(r)   r
+
+#else
+
+// Variant 2: Declare a conversion to an intermediate structure (see
+// below) that stores a non-constant pointer.
+struct StdBufRef
+{
+    StdBufRef(class StdBuf *Buf) : Buf(Buf) {}
+    class StdBuf *Buf;
+};
+struct StdStrBufRef
+{
+    StdStrBufRef(class StdStrBuf *Buf) : Buf(Buf) {}
+    class StdStrBuf *Buf;
+};
+#define moveRef(r) r
+#define mkRef(r)   StdBufRef(r)
+#define unRef(r)   (*r.Buf)
+
+#endif
+
 // Base buffer class. Either references or holds data.
 class StdBuf
 {
@@ -51,20 +88,6 @@
 	// Standard constructor
 	StdBuf() : fRef(true), pData(NULL), iSize(0) { }
 
-	// Constructor from other buffer (copy construction):
-	// Will take over buffer ownership. Copies data if specified.
-	// Note: Construct with Buf2.getRef() to construct a reference (This will work for a constant Buf2, too)
-	StdBuf(StdBuf & Buf2, bool fCopy = false)
-			: fRef(true), pData(NULL), iSize(0)
-	{
-		if (fCopy)
-			Copy(Buf2);
-		else if (!Buf2.isRef())
-			Take(std::move(Buf2));
-		else
-			Ref(Buf2);
-	}
-#ifdef HAVE_RVALUE_REF
 	StdBuf(const StdBuf & Buf2, bool fCopy = true)
 			: fRef(true), pData(NULL), iSize(0)
 	{
@@ -73,17 +96,15 @@
 		else
 			Ref(Buf2);
 	}
-	StdBuf(StdBuf RREF Buf2, bool fCopy = false)
+
+	StdBuf(StdBufRef Buf2)
 			: fRef(true), pData(NULL), iSize(0)
 	{
-		if (fCopy)
-			Copy(Buf2);
-		else if (!Buf2.isRef())
-			Take(std::move(Buf2));
+		if (!unRef(Buf2).isRef())
+			Take(moveRef(Buf2));
 		else
-			Ref(Buf2);
+			Ref(unRef(Buf2));
 	}
-#endif
 
 	// Set by constant data. Copies data if desired.
 	StdBuf(const void *pData, size_t iSize, bool fCopy = false)
@@ -97,7 +118,9 @@
 		Clear();
 	}
 
-	ALLOW_TEMP_TO_REF(StdBuf)
+#ifndef HAVE_RVALUE_REF
+    operator StdBufRef() { return StdBufRef(this); }
+#endif
 
 protected:
 
@@ -296,16 +319,10 @@
 		return StdBuf(getData(), getSize());
 	}
 	// take over another buffer's contents
-	void Take(StdBuf & Buf2)
+	void Take(StdBufRef Buf2)
 	{
-		Take(Buf2.GrabPointer(), Buf2.getSize());
+		Take(unRef(Buf2).GrabPointer(), unRef(Buf2).getSize());
 	}
-#ifdef HAVE_RVALUE_REF
-	void Take(StdBuf RREF Buf2)
-	{
-		Take(Buf2.GrabPointer(), Buf2.getSize());
-	}
-#endif
 
 	// * File support
 	bool LoadFromFile(const char *szFile);
@@ -337,9 +354,9 @@
 	bool operator != (const StdBuf &Buf2) const { return ! operator == (Buf2); }
 
 	// Set (as constructor: take if possible)
-	StdBuf &operator = (StdBuf RREF Buf2)
+	StdBuf &operator = (StdBufRef Buf2)
 	{
-		if (Buf2.isRef()) Ref(Buf2); else Take(std::move(Buf2));
+		if (unRef(Buf2).isRef()) Ref(Buf2); else Take(moveRef(Buf2));
 		return *this;
 	}
 
@@ -389,14 +406,6 @@
 	StdCopyBuf(const StdCopyBuf &Buf2, bool fCopy = true)
 			: StdBuf(Buf2.getRef(), fCopy)
 	{ }
-#ifdef HAVE_RVALUE_REF
-	StdCopyBuf(StdBuf RREF Buf2, bool fCopy = false)
-			: StdBuf(std::move(Buf2), fCopy)
-	{ }
-	StdCopyBuf(StdCopyBuf RREF Buf2, bool fCopy = false)
-			: StdBuf(std::move(Buf2), fCopy)
-	{ }
-#endif
 
 	// Set by constant data. Copies data by default.
 	StdCopyBuf(const void *pData, size_t iSize, bool fCopy = true)
@@ -424,21 +433,16 @@
 	// the StdBuf constructor. Without it, the const lvalue
 	// StdBuf constructor will be used, which will ref the contents
 	// instead of moving them.
-	StdStrBuf(StdStrBuf & Buf2, bool fCopy = false)
+	StdStrBuf(StdStrBufRef Buf2)
 //			: StdBuf(static_cast<StdStrBuf &>(Buf2), fCopy)
-			: StdBuf(Buf2, fCopy)
+            : StdBuf(mkRef(unRef(Buf2)))
 	{ }
 
-#ifdef HAVE_RVALUE_REF
 	// This constructor is important, because the compiler will create one
 	// otherwise, despite having two other constructors to choose from
 	StdStrBuf(const StdStrBuf & Buf2, bool fCopy = true)
 			: StdBuf(Buf2, fCopy)
 	{ }
-	StdStrBuf(StdStrBuf RREF Buf2, bool fCopy = false)
-			: StdBuf(std::move(Buf2), fCopy)
-	{ }
-#endif
 
 	// Set by constant data. References data by default, copies if specified.
 	explicit StdStrBuf(const char *pData, bool fCopy = false)
@@ -466,7 +470,9 @@
 			: StdBuf(pData, pData ? iLength + 1 : 0, fCopy)
 	{ }
 
-	ALLOW_TEMP_TO_REF(StdStrBuf)
+#ifndef HAVE_RVALUE_REF
+    operator StdStrBufRef() { return StdStrBufRef(this); }
+#endif
 
 public:
 
@@ -494,11 +500,8 @@
 
 	void Ref(const StdStrBuf &Buf2) { StdBuf::Ref(Buf2.getData(), Buf2.getSize()); }
 	StdStrBuf getRef() const { return StdStrBuf(getData(), getLength()); }
-	void Take(StdStrBuf & Buf2) { StdBuf::Take(Buf2); }
-#ifdef HAVE_RVALUE_REF
-	void Take(StdStrBuf RREF Buf2) { StdBuf::Take(std::move(Buf2)); }
-#endif
-	
+	void Take(StdStrBufRef Buf2) { StdBuf::Take(moveRef(mkRef(unRef(Buf2)))); }
+
 	void Clear() { StdBuf::Clear(); }
 	void Copy() { StdBuf::Copy(); }
 	void Copy(const char *pnData) { StdBuf::Copy(pnData, pnData ? std::strlen(pnData) + 1 : 0); }
@@ -720,14 +723,6 @@
 	StdCopyStrBuf(const StdCopyStrBuf &Buf2, bool fCopy = true)
 			: StdStrBuf(Buf2.getRef(), fCopy)
 	{ }
-#ifdef HAVE_RVALUE_REF
-	StdCopyStrBuf(StdStrBuf RREF Buf2, bool fCopy = false)
-			: StdStrBuf(std::move(Buf2), fCopy)
-	{ }
-	StdCopyStrBuf(StdCopyStrBuf RREF Buf2, bool fCopy = false)
-			: StdStrBuf(std::move(Buf2), fCopy)
-	{ }
-#endif
 
 	// Set by constant data. Copies data if desired.
 	explicit StdCopyStrBuf(const char *pData, bool fCopy = true)
