diff options
| author | 2014-07-16 09:07:57 +0200 | |
|---|---|---|
| committer | 2014-07-16 09:08:19 +0200 | |
| commit | 15ab5382a553a47f21fe7283010ccdb342c0ead6 (patch) | |
| tree | 3574ab838cf91b43a34642566b1d63e8368a1ac7 /src/common/bit_field.h | |
| parent | BitField: Add an explicit evaluation method. (diff) | |
| download | yuzu-15ab5382a553a47f21fe7283010ccdb342c0ead6.tar.gz yuzu-15ab5382a553a47f21fe7283010ccdb342c0ead6.tar.xz yuzu-15ab5382a553a47f21fe7283010ccdb342c0ead6.zip | |
BitField: Delete copy assignment to prevent obscure bugs.
Cf. https://github.com/dolphin-emu/dolphin/pull/483
Diffstat (limited to '')
| -rw-r--r-- | src/common/bit_field.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/common/bit_field.h b/src/common/bit_field.h index a39bb9886..c28e722c8 100644 --- a/src/common/bit_field.h +++ b/src/common/bit_field.h | |||
| @@ -124,6 +124,22 @@ public: | |||
| 124 | // so that we can use this within unions | 124 | // so that we can use this within unions |
| 125 | BitField() = default; | 125 | BitField() = default; |
| 126 | 126 | ||
| 127 | #ifndef _WIN32 | ||
| 128 | // We explicitly delete the copy assigment operator here, because the | ||
| 129 | // default copy assignment would copy the full storage value, rather than | ||
| 130 | // just the bits relevant to this particular bit field. | ||
| 131 | // Ideally, we would just implement the copy assignment to copy only the | ||
| 132 | // relevant bits, but this requires compiler support for unrestricted | ||
| 133 | // unions. | ||
| 134 | // MSVC 2013 has no support for this, hence we disable this code on | ||
| 135 | // Windows (so that the default copy assignment operator will be used). | ||
| 136 | // For any C++11 conformant compiler we delete the operator to make sure | ||
| 137 | // we never use this inappropriate operator to begin with. | ||
| 138 | // TODO: Implement this operator properly once all target compilers | ||
| 139 | // support unrestricted unions. | ||
| 140 | BitField& operator=(const BitField&) = delete; | ||
| 141 | #endif | ||
| 142 | |||
| 127 | __forceinline BitField& operator=(T val) | 143 | __forceinline BitField& operator=(T val) |
| 128 | { | 144 | { |
| 129 | storage = (storage & ~GetMask()) | ((val << position) & GetMask()); | 145 | storage = (storage & ~GetMask()) | ((val << position) & GetMask()); |