This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/57053] New: inaccurate message for ambiguous calls when in fact there is not valid candidate


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57053

             Bug #: 57053
           Summary: inaccurate message for ambiguous calls when in fact
                    there is not valid candidate
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: akim.demaille@gmail.com


Hi all,

This is not a genuine bug report, I just wanted to point out that the error
message is not as clear as it could be: G++ uses "ambiguity" both to name the
situation where there are too many candidates, or not enough (ie. 0).  In the
latter case, it would be more appropriate that there _no_ viable candidate,
instead of an "ambiguity".

My â0.02, meant to be useful.

$ cat foo.cc
int foo(int*);
int foo(char*);

int bar(int);

int main ()
{
  foo(0);
  foo(1);
  bar("foo");
}


$ g++-mp-4.8 /tmp/foo.cc
/tmp/foo.cc: In function 'int main()':
/tmp/foo.cc:8:8: error: call of overloaded 'foo(int)' is ambiguous
   foo(0);
        ^
/tmp/foo.cc:8:8: note: candidates are:
/tmp/foo.cc:1:5: note: int foo(int*)
 int foo(int*);
     ^
/tmp/foo.cc:2:5: note: int foo(char*)
 int foo(char*);
     ^
/tmp/foo.cc:9:8: error: call of overloaded 'foo(int)' is ambiguous
   foo(1);
        ^
/tmp/foo.cc:9:8: note: candidates are:
/tmp/foo.cc:1:5: note: int foo(int*) <near match>
 int foo(int*);
     ^
/tmp/foo.cc:1:5: note:   no known conversion for argument 1 from 'int' to
'int*'
/tmp/foo.cc:2:5: note: int foo(char*) <near match>
 int foo(char*);
     ^
/tmp/foo.cc:2:5: note:   no known conversion for argument 1 from 'int' to
'char*'
/tmp/foo.cc:10:12: error: invalid conversion from 'const char*' to 'int'
[-fpermissive]
   bar("foo");
            ^
/tmp/foo.cc:4:5: error:   initializing argument 1 of 'int bar(int)'
[-fpermissive]
 int bar(int);
     ^

For the records, clang.

$ clang++ /tmp/foo.cc
/tmp/foo.cc:8:3: error: call to 'foo' is ambiguous
  foo(0);
  ^~~
/tmp/foo.cc:1:5: note: candidate function
int foo(int*);
    ^
/tmp/foo.cc:2:5: note: candidate function
int foo(char*);
    ^
/tmp/foo.cc:9:3: error: no matching function for call to 'foo'
  foo(1);
  ^~~
/tmp/foo.cc:1:5: note: candidate function not viable: no known conversion from
'int' to
      'int *' for 1st argument
int foo(int*);
    ^
/tmp/foo.cc:2:5: note: candidate function not viable: no known conversion from
'int' to
      'char *' for 1st argument
int foo(char*);
    ^
/tmp/foo.cc:10:3: error: no matching function for call to 'bar'
  bar("foo");
  ^~~
/tmp/foo.cc:4:5: note: candidate function not viable: no known conversion from
      'const char [4]' to 'int' for 1st argument
int bar(int);
    ^
3 errors generated.
$


(Also, please note that the fact that G++ gives a signature (int foo(int)) is
somewhat misleading, as 0 and 1 do not behave equally here.)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]