[cfe-dev] error: use of overloaded operator '==' is ambiguous

Douglas Gregor dgregor at apple.com
Fri Jul 30 14:57:53 PDT 2010

On Jul 30, 2010, at 2:55 PM, Shawn Erickson wrote:

> Thanks Doug for that analysis.
> Quick question why is long double being listed in the following
> diagnostic? I don't believe either type at that line are floating
> point (the const Status::eNo is int64_t) unless this is some fallback
> promotion.
> [0:657] > flc -c issue_002.cpp
> issue_002.cpp:78:21: error: use of overloaded operator '==' is ambiguous
>   if (Status::eNo == bar.isEmpty()) {
>       ~~~~~~~~~~~ ^  ~~~~~~~~~~~~~
> issue_002.cpp:78:21: note: because of ambiguity in conversion of
> 'ResultCode' (aka 'ResultCodeClass') to 'long double'

It doesn't matter that 'long double' itself isn't used. All of the builtin candidates are required to be in the overload set, per C++ 13.6 [over.built]p12:

For every pair of promoted arithmetic types L and R, there exist candidate operator functions of the form
	LR	operator*(L, R); 
	LR	operator/(L, R); 
	LR	operator+(L, R); 
	LR	operator-(L, R); 
	bool	operator<(L, R); 
	bool	operator>(L, R); 
	bool	operator<=(L, R); 
	bool	operator>=(L, R); 
	bool	operator==(L, R); 
	bool	operator!=(L, R);

where LR is the result of the usual arithmetic conversions between types L and R.

It's possible that GCC was attempting to optimize by not providing the candidates involving floating-point types, but that optimization would be incorrect.

	- Doug

More information about the cfe-dev mailing list