Skip to content

Commit

Permalink
[meta] Declare bool conversion operators as explicit
Browse files Browse the repository at this point in the history
Non-explicit conversion operators in general can participate in very
surprising conversion chains. Explicit bool operator is a good place to
start with, because even with explicit they do get automatic contextual
conversion in a lot of places, e.g., if conditions.
  • Loading branch information
ishitatsuyuki authored and doitsujin committed Jan 27, 2024
1 parent afc6aa7 commit e2a46a3
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/d3d9/d3d9_mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace dxvk {
D3D9Memory (D3D9Memory&& other);
D3D9Memory& operator = (D3D9Memory&& other);

operator bool() const { return m_chunk != nullptr; }
explicit operator bool() const { return m_chunk != nullptr; }

void Map();
void Unmap();
Expand Down Expand Up @@ -139,7 +139,7 @@ namespace dxvk {
D3D9Memory (D3D9Memory&& other);
D3D9Memory& operator = (D3D9Memory&& other);

operator bool() const { return m_ptr != nullptr; }
explicit operator bool() const { return m_ptr != nullptr; }

void Map() {}
void Unmap() {}
Expand Down
4 changes: 2 additions & 2 deletions src/d3d9/d3d9_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ namespace dxvk {
const T* operator & () const { ensure(); return m_data.get(); }
T* operator & () { ensure(); return m_data.get(); }

operator bool() { return m_data != nullptr; }
explicit operator bool() const { return m_data != nullptr; }
operator T() { ensure(); return *m_data; }

void ensure() const { if (!m_data) m_data = std::make_unique<T>(); }
Expand All @@ -213,7 +213,7 @@ namespace dxvk {

T& operator=(const T& x) { m_data = x; return m_data; }

operator bool() { return true; }
explicit operator bool() const { return true; }
operator T() { return m_data; }

const T* operator -> () const { return &m_data; }
Expand Down
2 changes: 1 addition & 1 deletion src/dxbc/dxbc_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ namespace dxvk {
return out;
}

operator bool () const {
explicit operator bool () const {
return m_mask != 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/dxvk/dxvk_cs.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ namespace dxvk {
return m_chunk;
}

operator bool () const {
explicit operator bool () const {
return m_chunk != nullptr;
}

Expand Down
2 changes: 1 addition & 1 deletion src/dxvk/dxvk_extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace dxvk {
* provided by the extension can be used.
* \returns \c true if the extension is enabled
*/
operator bool () const {
explicit operator bool () const {
return m_revision != 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/dxvk/dxvk_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ namespace dxvk {
* \returns \c true if this slice points to actual device
* memory, and \c false if it is undefined.
*/
operator bool () const {
explicit operator bool () const {
return m_memory != VK_NULL_HANDLE;
}

Expand Down
4 changes: 2 additions & 2 deletions src/dxvk/dxvk_sparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ namespace dxvk {
return m_page != other.m_page;
}

operator bool () const {
explicit operator bool () const {
return m_page != nullptr;
}

Expand Down Expand Up @@ -341,7 +341,7 @@ namespace dxvk {
* \brief Checks whether page table is defined
* \returns \c true if the page table is defined
*/
operator bool () const {
explicit operator bool () const {
return m_buffer || m_image;
}

Expand Down

0 comments on commit e2a46a3

Please sign in to comment.