wyszukiwanie funkcji szablonów dla przyjaciół
Poniższy prosty kod dobrze się kompiluje
class A {
int x[3];
public:
A() { x[0]=1; x[1]=2; x[2]=3; }
friend int const&at(A const&a, unsigned i) noexcept
{
return a.x[i];
}
friend int foo(A const&a, unsigned i) noexcept
{
int tmp = at(a,i);
return tmp*tmp;
}
};
ale jeśli przyjaciele zrobią szablony
class A {
int x[3];
public:
A() { x[0]=1; x[1]=2; x[2]=3; }
template<unsigned I>
friend int const&at(A const&a) noexcept
{
static_assert(I<3,"array boundary exceeded");
return a.x[I];
}
template<unsigned I>
friend int foo(A const&a) noexcept
{
int tmp = at<I>(a); // <- error: use of undeclared identifier 'at'
return tmp*tmp;
}
};
reguły wyszukiwania zmieniają się i clang narzeka na ten błąd, ale gcc i icpc nie. Kto ma rację (C ++ 11)? i jak naprawić kod dla clang?