<html>
    <head>
      <base href="http://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 --- - Problem with in-class frient function template"
   href="http://llvm.org/bugs/show_bug.cgi?id=20433">20433</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Problem with in-class frient function template
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>unspecified
          </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>-New Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>jpr@polytech.unice.fr
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The following (minimalized) program fails to compile with clang++ 3.4 (release)
and clang  3.5.0 (trunk 213845) (llvm/trunk 213844):

struct A {
    template <typename U> 
    friend U f(const A& a) {return U{};}
};

int main() {
    A a;
    double x = f<double>(a);
}

Here is the corresponding error message:

clang++ -std=c++11 -Wall infriend.cpp 
infriend.cpp:8:16: error: use of undeclared identifier 'f'
    double x = f<double>(A{});
               ^
infriend.cpp:8:24: error: expected '(' for function-style cast or type
construction
    double x = f<double>(A{});
                 ~~~~~~^

The program compiles if I define the body of function f() outside the class:

struct A {
    template <typename U> 
    friend U f(const A& a); 
};

template <typename U> 
inline U f(const A& a) {return U{};}

int main() {
    A a;
    double x = f<double>(a);
}

However, this solution is impossible if struct A is itself a template. We
**have to** define it within the class, don't we? 

template <typename T>
struct A {
    template <typename U> 
    friend U f(const A& a) {return U{};}
};

int main() {
    A<int> a;
    double x = f<double>(a);
}

and compilation fails with the same message as above.

Note that gcc-4.8.x/4.9.x compiles correctly these examples.</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>