Make comparison operator member functions const
...which avoids overload resolution ambiguities in C++20, when a synthesized
candidate of operator == for a reversed-argument rewrite conflicts with the
actual operator ==, due to the asymmetric const-ness of the implicit object
parameter and the RHS parameter. (As observed with recent Clang 10 trunk with
-std=c++2a:
> vcl/unx/generic/gdi/salgdi.cxx:138:18: error: use of overloaded operator '!=' is ambiguous (with operand types 'SalX11Screen' and 'SalX11Screen')
> if( nXScreen != m_nXScreen )
> ~~~~~~~~ ^ ~~~~~~~~~~
> vcl/inc/unx/saltype.h:22:10: note: candidate function
> bool operator!=(const SalX11Screen &rOther) { return rOther.mnXScreen != mnXScreen; }
> ^
> vcl/inc/unx/saltype.h:21:10: note: candidate function
> bool operator==(const SalX11Screen &rOther) { return rOther.mnXScreen == mnXScreen; }
> ^
> vcl/inc/unx/saltype.h:21:10: note: candidate function (with reversed parameter order)
)
Change-Id: I5dab4fecfbb7badab06ebd0d779527de9672a02a
Reviewed-on: https://gerrit.libreoffice.org/81352
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
diff --git a/vcl/inc/unx/saltype.h b/vcl/inc/unx/saltype.h
index 97d9f1a..e62bdd2 100644
--- a/vcl/inc/unx/saltype.h
+++ b/vcl/inc/unx/saltype.h
@@ -18,8 +18,8 @@ class SalX11Screen {
public:
explicit SalX11Screen(unsigned int nXScreen) : mnXScreen( nXScreen ) {}
unsigned int getXScreen() const { return mnXScreen; }
bool operator==(const SalX11Screen &rOther) { return rOther.mnXScreen == mnXScreen; }
bool operator!=(const SalX11Screen &rOther) { return rOther.mnXScreen != mnXScreen; }
bool operator==(const SalX11Screen &rOther) const { return rOther.mnXScreen == mnXScreen; }
bool operator!=(const SalX11Screen &rOther) const { return rOther.mnXScreen != mnXScreen; }
};
#endif // INCLUDED_VCL_INC_UNX_SALTYPE_H