<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Arbitrary overload resolution on template function instead of "ambiguous overload" error"
   href="https://llvm.org/bugs/show_bug.cgi?id=25669">25669</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Arbitrary overload resolution on template function instead of "ambiguous overload" error
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.7
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++11
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>poletti.marco@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The code below is a minimal code sample that exhibits the bug.
The type FindInMap<Map, int>::type should be `void' but Clang thinks it's
`char'.
This works correctly in GCC (tested version 4.8.5) but fails in Clang 3.7.0.

Explanation:
* The first overload of f (templated) is ambiguous (both Value=char and
Value=float match, with the same priority since both require a conversion from
Map* to the respective Pair<...>*) so it should be discarded.
* The second overload of f (non-templated) is the only one that remains and
therefore is the one that should be picked.

What's even more puzzling is that if the non-templated f is commented out, then
Clang displays the ambiguous overload error (which is correct) but for some
reason that's otherwise ignored.

template <typename T, typename U>
struct Pair {};

template <typename M, typename T>
struct FindInMap {
    template <typename Value>
    static Value f(Pair<T, Value>*);

    static void f(void*);

    using type = decltype(f((M*)0));
};

struct Map : public Pair<int, float>, Pair<int, char> {};

#include <functional> // Just for std::is_same
static_assert(std::is_same<FindInMap<Map, int>::type, void>::value, "");</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>