yuzu-emu
/
yuzu
Archived
1
0
Fork 0

BitField: Delete copy assignment to prevent obscure bugs.

Cf. https://github.com/dolphin-emu/dolphin/pull/483
This commit is contained in:
Tony Wasserka 2014-07-16 09:07:57 +02:00
parent 47a001722d
commit 15ab5382a5
1 changed files with 16 additions and 0 deletions

View File

@ -124,6 +124,22 @@ public:
// so that we can use this within unions
BitField() = default;
#ifndef _WIN32
// We explicitly delete the copy assigment operator here, because the
// default copy assignment would copy the full storage value, rather than
// just the bits relevant to this particular bit field.
// Ideally, we would just implement the copy assignment to copy only the
// relevant bits, but this requires compiler support for unrestricted
// unions.
// MSVC 2013 has no support for this, hence we disable this code on
// Windows (so that the default copy assignment operator will be used).
// For any C++11 conformant compiler we delete the operator to make sure
// we never use this inappropriate operator to begin with.
// TODO: Implement this operator properly once all target compilers
// support unrestricted unions.
BitField& operator=(const BitField&) = delete;
#endif
__forceinline BitField& operator=(T val)
{
storage = (storage & ~GetMask()) | ((val << position) & GetMask());