<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 --- - Call to friend function template of a class template considered ambiguous"
   href="https://llvm.org/bugs/show_bug.cgi?id=31507">31507</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Call to friend function template of a class template considered ambiguous
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>trunk
          </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++
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>t@sharklasers.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 following code attempts to declare a function template as a friend to a
class template and defines it subsequently:

template <typename T>
class A {

    template <typename T1, typename T2>
    friend auto func(T1 a, T2 b);

private:
    T a;
};

template <typename T1, typename T2>
auto func(T1 x, T2 y) {
    return x.a + y.a;
}

int main() {
    A<int> a;
    A<double> b;

    func(a, b);
}

Clang version 4.0.0 (trunk 290784) rejects this code saying:
test.cpp:21:5: error: call to 'func' is ambiguous
    func(a, b);
    ^~~~
test.cpp:6:17: note: candidate function [with T1 = A<int>, T2 = A<double>]
    friend auto func(T1 a, T2 b);
                ^
test.cpp:13:6: note: candidate function [with T1 = A<int>, T2 = A<double>]
auto func(T1 x, T2 y) {

GCC, ICC and MSVC accept that code. With the following change:

template <typename T>
class A {

    template <typename T1, typename T2>
    friend auto func(T1 x, T2 y) {
        return x.a + y.a;
    }

private:
    T a;
};

int main() {
    A<int> a;
    A<double> b;

    func(a, b);
}

Clang accepts, however GCC, ICC and MSVC reject with similar error messages:
test.cpp: In instantiation of ‘class A<double>’:
test.cpp:16:15:   required from here
test.cpp:6:17: error: redefinition of ‘template<class T1, class T2> auto
func(T1, T2)’
     friend auto func(T1 x, T2 y) {
                 ^~~~
test.cpp:6:17: note: ‘template<class T1, class T2> auto func(T1, T2)’
previously defined here
test.cpp: In instantiation of ‘auto func(T1, T2) [with T1 = A<int>; T2 =
A<double>; T = int]’:</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>