Hi,
While compiling this (very simplified) code under Linux
<<<<start<<<<<<<
class C {
public:
C(char);
};
const C operator+(char c1, const C & s2);
enum E { a, b };
E f(char c)
{
return (E) (c + a); // + ambiguous ?
}
>>>>>end>>>>>>>>
g++ indicates that '+' in f() is ambiguous :
f.c:13: error: ISO C++ says that these are ambiguous, even though the worst
conversion for the first is better than the worst conversion for the second:
f.c:13: note: candidate 1: operator+(int, int) <built-in>
f.c:6: note: candidae 2: const C operator+(char, const C&)
Frankly I am surprized, conversion from an enum -> "int" seem natural
contrarily to the one from an enum -> char -> "const C &" using "C(char)"
Obviously it is easy to write "(int) c + a" or "c + (int) a" to solve this
problem.
I apologize if this code is really ambiguous
Best regards
Bruno Pages
--
Summary: g++ says 'ambiguous call'
Product: gcc
Version: 4.0.2
Status: UNCONFIRMED
Severity: minor
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: bru dot pages at wanadoo dot fr
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24485