According to the standard, friend function declared and defined in class can only be find by ADL. So, I think the following code should compile.
template<int M>
struct test{
template<int N = 0>
friend void foo(test){}
};
int main(){
test<2> t;
foo(t);// compile
foo<1>(t);// error
}
However, gcc gives the following error:
main.cpp: In function 'int main()':
main.cpp:10:5: error: 'foo' was not declared in this scope
foo<1>(t);
^~~
Then, I have three problems.
- Should
template<int N> foo
be found according to the standard? - Why
foo
is found whilefoo<1>
is not? - Is there a workaround besides defining
foo
outside?