I have a template class with a private constructor which is to be friends of every typed instance of the class. The following compiles under g++ 11.4.0 but fails under clang++ version 14.0.0-1ubuntu1.1
template <typename T>
class foo {
foo(T){}
template <typename U> friend foo<U>::foo(U);
public:
foo(){}
};
int main() {
foo<int> a{};
}
clang gives the error
main.cpp:4:34: error: missing 'typename' prior to dependent type name 'foo<U>::foo'
template <typename U> friend foo<U>::foo(U);
^~~~~~~~~~~
typename
main.cpp:4:46: error: friends can only be classes or functions
template <typename U> friend foo<U>::foo(U);
I don't think foo<U>::foo
is a dependent type name, but at any rate adding typename as suggested results in the error
main.cpp:4:55: error: friends can only be classes or functions
template <typename U> friend typename foo<U>::foo(U);
foo<T>::foo(T)
andfoo<U>::foo(U)
? Most importantly, what code are you hoping to write in the constructor (or elsewhere) that requires it to be a friend? – Gracetypename
)? – SienkiewiczU
toconst U&
, clang starts complaining that it expected a semicolon instead of a parameter list. So an underlying issue looks like clang does not see the friend as a function declaration. – Sienkiewicztemplate <typename U> friend class foo<U>;
? – Impeccable