Bug 24485 - g++ says 'ambiguous call'
Summary: g++ says 'ambiguous call'
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.2
: P2 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-10-22 15:28 UTC by Bruno Pages
Modified: 2005-10-22 17:58 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bruno Pages 2005-10-22 15:28:29 UTC
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
Comment 1 Andrew Pinski 2005-10-22 17:46:15 UTC
The C++ standard says they are ambiguous.
Comment 2 Bruno Pages 2005-10-22 17:58:07 UTC
(In reply to comment #1)
> The C++ standard says they are ambiguous.
> 

ok, in this case g++ 3.3.3 is wrong because it says nothing, even with -Wall

regards