Consider this code:
template <int N> struct X { friend void f(X *) {} }; int main() { f((X<0> *)0);
Compilers
seem to heavily disagree. (MSVC08 / 10 says no, GCC <4.5 says yes, but 4.5 says no, Sun 5.1 says yes, Intel 11.1 says yes, but goau says no (both are EDG )).
According to "C ++ Templates - The Complete Guide":
... it is assumed that the call including finding friends in related classes is actually the class to be created ... Although this was clearly intended for those who wrote the C ++ standard, this is not clearly stated in the standard.
I could not find the corresponding section in the standard. Any link?
Consider this variation:
template <int N> struct X { template <int M> friend void f(X<M> *) {} }; template <> struct X<0> { }; int main() { X<1>(); f((X<0> *)0);
The key problem here is that the viable function introduced by X<1> should be visible during ADL for X<0> ? Are they related? All the compilers mentioned above accept this code, with the exception of Comeau, which only accepts it in relaxed mode. Not sure what the standard should say about this.
What do you take on?
c ++ templates argument-dependent-lookup friend-function
uj2
source share