[LLVMbugs] [Bug 20433] New: Problem with in-class frient function template
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Thu Jul 24 03:04:55 PDT 2014
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: unassignedclangbugs at nondot.org
Reporter: jpr at polytech.unice.fr
CC: llvmbugs at cs.uiuc.edu
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140724/20cd3872/attachment.html>
More information about the llvm-bugs
mailing list