https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67708

            Bug ID: 67708
           Summary: ambiguous overload for user-defined conversion
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: crazii.he at yahoo dot com
  Target Milestone: ---
              Host: Win32
            Target: Android

command line: g++ ./sample.cxx

sample.cxx:
----------------------------------------
class String
{
public:
        String();
};

class Value
{
public:
        operator const String&();
        operator int() const;
};

class Concat
{
public:
        Concat();
        Concat& operator+(const String&);
        Concat& operator+(const char&);
};


int main()
{
        Value v;
        Concat concat;
        concat = concat + v + 'A';
}
----------------------------------------
output:
./sample.cxx: In function 'int main()':
./sample.cxx:28:18: error: ambiguous overload for 'operator+' (operand types
are 'Concat' and 'Value')
  concat = concat + v + 'A';
                  ^
./sample.cxx:28:18: note: candidates are:
./sample.cxx:19:10: note: Concat& Concat::operator+(const String&)
  Concat& operator+(const String&);
          ^
./sample.cxx:20:10: note: Concat& Concat::operator+(const char&)
  Concat& operator+(const char&);
          ^

please IGNORE linking messages if there's any.
-----------------------------------------
according to C++ standard, this behavior is OK.

but IMHO, 
the compiler can pick the best match on 'operator+(const String&)'
since it doesn't need extra conversion after user-defined conversion,
yet 'operator+(int)' need convert int to char after user-define conversion.

So I Suggest it as a ENHANCEMENT, if it doesn't conflict with the C++ standard.

Reply via email to