diff --git a/src/addrman.h b/src/addrman.h --- a/src/addrman.h +++ b/src/addrman.h @@ -55,7 +55,7 @@ template inline void SerializationOp(Stream &s, Operation ser_action) { - READWRITE(*static_cast(this)); + READWRITEAS(CAddress, *this); READWRITE(source); READWRITE(nLastSuccess); READWRITE(nAttempts); diff --git a/src/primitives/block.h b/src/primitives/block.h --- a/src/primitives/block.h +++ b/src/primitives/block.h @@ -77,7 +77,7 @@ template inline void SerializationOp(Stream &s, Operation ser_action) { - READWRITE(*static_cast(this)); + READWRITEAS(CBlockHeader, *this); READWRITE(vtx); } diff --git a/src/protocol.h b/src/protocol.h --- a/src/protocol.h +++ b/src/protocol.h @@ -396,7 +396,7 @@ uint64_t nServicesInt = nServices; READWRITE(nServicesInt); nServices = static_cast(nServicesInt); - READWRITE(*static_cast(this)); + READWRITEAS(CService, *this); } // TODO: make private (improves encapsulation) diff --git a/src/script/script.h b/src/script/script.h --- a/src/script/script.h +++ b/src/script/script.h @@ -433,7 +433,7 @@ template inline void SerializationOp(Stream &s, Operation ser_action) { - READWRITE(static_cast(*this)); + READWRITEAS(CScriptBase, *this); } CScript &operator+=(const CScript &b) { diff --git a/src/serialize.h b/src/serialize.h --- a/src/serialize.h +++ b/src/serialize.h @@ -152,7 +152,18 @@ SER_GETHASH = (1 << 2), }; +//! Convert the reference base type to X, without changing constness or +//! reference type. +template X &ReadWriteAsHelper(X &x) { + return x; +} +template const X &ReadWriteAsHelper(const X &x) { + return x; +} + #define READWRITE(...) (::SerReadWriteMany(s, ser_action, __VA_ARGS__)) +#define READWRITEAS(type, obj) \ + (::SerReadWriteMany(s, ser_action, ReadWriteAsHelper(obj))) /** * Implement three methods for serializable objects. These are actually wrappers diff --git a/src/txdb.h b/src/txdb.h --- a/src/txdb.h +++ b/src/txdb.h @@ -50,7 +50,7 @@ template inline void SerializationOp(Stream &s, Operation ser_action) { - READWRITE(*static_cast(this)); + READWRITEAS(CDiskBlockPos, *this); READWRITE(VARINT(nTxOffset)); } diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -386,7 +386,7 @@ mapValueCopy["timesmart"] = strprintf("%u", nTimeSmart); } - s << *static_cast(this); + s << static_cast(*this); //!< Used to be vtxPrev std::vector vUnused; s << vUnused << mapValueCopy << vOrderForm << fTimeReceivedIsTxTime @@ -397,7 +397,7 @@ Init(nullptr); char fSpent; - s >> *static_cast(this); + s >> static_cast(*this); //!< Used to be vtxPrev std::vector vUnused; s >> vUnused >> mapValue >> vOrderForm >> fTimeReceivedIsTxTime >>