[llvm-bugs] [Bug 32073] New: Clang doesn't align with MSVC/GCC behaviour for an ambiguous method call

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Feb 26 21:03:52 PST 2017


http://bugs.llvm.org/show_bug.cgi?id=32073

            Bug ID: 32073
           Summary: Clang doesn't align with MSVC/GCC behaviour for an
                    ambiguous method call
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: hughbellars at gmail.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

The code below fails to compile with GCC (4.9.2) or MSVC (Visual Studio 2015
Update 3). Clang prints "1".

#include <iostream>

void addChild(uint64_t) { std::cout << "1"; }
void addChild(const char*) { std::cout << "2"; }

int main()
{
    addChild(unsigned(0));
}

Fixing this would obviously be a breaking change - I suggest a warning as a
better thing to do.

Obviously in this case, the method call is ambiguous, unsigned(0) can be an
uint64_t(0) or const char*(NULL)

GCC errors:
prog.cpp:10:25: error: call of overloaded 'addChild(unsigned int)' is ambiguous
     addChild(unsigned(0));
                         ^
prog.cpp:10:25: note: candidates are:
prog.cpp:5:6: note: void addChild(uint64_t)
 void addChild(uint64_t) { std::cout << "1"; }
      ^
prog.cpp:6:6: note: void addChild(const char*)
 void addChild(const char*) { std::cout << "2"; }

MSVC errors:
source_file.cpp(10): error C2668: 'addChild': ambiguous call to overloaded
function
source_file.cpp(6): note: could be 'void addChild(const char *)'
source_file.cpp(5): note: or       'void addChild(uint64_t)'
source_file.cpp(10): note: while trying to match the argument list '(unsigned
int)'

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170227/dda28366/attachment.html>


More information about the llvm-bugs mailing list