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

            Bug ID: 20433
           Summary: Problem with in-class frient function template
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    Classification: Unclassified

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to