"Richard Guenther" <[EMAIL PROTECTED]> writes: > > > On Jan 17, 2008 2:12 PM, Dragan Milenkovic <[EMAIL PROTECTED]> wrote: > > > > Richard Guenther wrote: > > > > [snip] > > > > >> template <typename T> > > > > >> struct Foo > > > > >> { > > > > >> template <typename Z> > > > > >> friend void func(const Foo &); > > > > >> }; > > > > >> > > > > >> void check(const Foo<int> & x) > > > > >> { > > > > >> // Foo<int> weird; // uncomment this line and all works > > > > >> > > > > >> func<int>(x); // <-- ERROR > > > > >> } > > > > >> > > > > >> > > > > >> Tested with gcc 4.0 - 4.3, and all behave the same: > > > > >> > > > > >> "error: 'func' was not declared in this scope" > > > > >> > > > > >> but it works if you uncomment the weird line. > > > > > > > > > > Actually even with the weird line the program is invalid. What are > > > > > you trying to do? ;) > > > > > > > > > > Richard. > > > > > > > > Ok... afaik, that func should be defined on that very place where it is > > > > declared as friend. But could you please elaborate why it is invalid, > > > > since you made me start questioning my C++ knowledge... :-D > > > > > > How should name-lookup find func? > > > > It should use argument dependent lookup. This is like the common case > > of > > > > class x > > { > > friend x operator+(const& x, const& x) { return x.var + x.var; } > > }; > > > > in which x::operator+ is found without taking special action. > > Well, first I think you'd need friend-injection or otherwise a global > decl of the function.
ADL works without friend injection. Look at 3.4.2 [basic.lookup.koenig] in C++98. > Second I thought argument dependent > name-lookup only applies to namespaces, not classes. No. > EDG rejects this consistently btw. Well, I'm probably misinterpreting the example. Adding the templates must change it somehow. For example, this works fine, even without -ffriend-injection: class x { friend x operator+(const x& x1, const x& x2); }; x foo(x x1, x x2) { return x1 + x2; } Ian