From 4b37749a62f9b57c5b92affba34157a2279b7fc6 Mon Sep 17 00:00:00 2001 From: Nicolas Hake Date: Sat, 9 May 2009 21:13:07 +0200 Subject: [PATCH] StdBuf: Disable const copy ctor on compilers not supporting rvalue references Otherwise, MSVC chooses the const ctor and loses underlying memory. This might be a good time to drop StdBuf and use std::string instead. --- standard/inc/Standard.h | 8 ++++++-- standard/inc/StdBuf.h | 15 ++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/standard/inc/Standard.h b/standard/inc/Standard.h index 34b87b762..c9540cee9 100644 --- a/standard/inc/Standard.h +++ b/standard/inc/Standard.h @@ -101,9 +101,13 @@ typedef __int32 intptr_t; #if defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) // Another temporary-to-reference-fix: this time using C++0x's rvalue references -#define RREF && +#define HAVE_RVALUE_REF +#endif + +#ifdef HAVE_RVALUE_REF +# define RREF && #else -#define RREF & +# define RREF & #endif #if defined(_DEBUG) && defined(_MSC_VER) diff --git a/standard/inc/StdBuf.h b/standard/inc/StdBuf.h index 310897ef9..1d33cdd9d 100644 --- a/standard/inc/StdBuf.h +++ b/standard/inc/StdBuf.h @@ -43,7 +43,7 @@ public: // 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 RREF Buf2, bool fCopy = false) + StdBuf(StdBuf RREF Buf2, bool fCopy = false) : fRef(true), pData(NULL), iSize(0) { if(fCopy) @@ -53,6 +53,7 @@ public: else Ref(Buf2); } +#ifdef HAVE_RVALUE_REF StdBuf(const StdBuf & Buf2, bool fCopy = true) : fRef(true), pData(NULL), iSize(0) { @@ -61,6 +62,7 @@ public: else Ref(Buf2); } +#endif // Set by constant data. Copies data if desired. StdBuf(const void *pData, size_t iSize, bool fCopy = false) @@ -274,7 +276,7 @@ public: } // take over another buffer's contents void Take(StdBuf RREF Buf2) - { + { Take(Buf2.GrabPointer(), Buf2.getSize()); } @@ -308,7 +310,7 @@ public: // Set (as constructor: take if possible) StdBuf &operator = (StdBuf RREF Buf2) - { + { if(Buf2.isRef()) Ref(Buf2); else Take(Buf2); return *this; } @@ -382,12 +384,15 @@ public: { } // See StdBuf::StdBuf. Will take data if possible. - StdStrBuf(StdStrBuf RREF Buf2, bool fCopy = false) + StdStrBuf(StdStrBuf RREF Buf2, bool fCopy = false) : StdBuf(Buf2, fCopy) { } - StdStrBuf(const StdStrBuf & Buf2, bool fCopy = true) + +#ifdef HAVE_RVALUE_REF + StdStrBuf(const StdStrBuf & Buf2, bool fCopy = true) : StdBuf(Buf2, fCopy) { } +#endif // Set by constant data. References data by default, copies if specified. explicit StdStrBuf(const char *pData, bool fCopy = false)