This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/38392] Template friend function injection



------- Comment #11 from H9XLrv5oXVNvHiUI at spambox dot us  2009-12-24 17:23 -------
This is possibly the part in which gets confirmed that the code is standard
compliant, although it reports the exact same paragraph you linked (the old
version):
http://groups.google.com/group/comp.lang.c++/tree/browse_frm/thread/493afd501c807ffe/68c709135884bac7?rnum=11&_done=%2Fgroup%2Fcomp.lang.c%2B%2B%2Fbrowse_frm%2Fthread%2F493afd501c807ffe%3F#doc_38f8441247122dcd

I guess that page is some kind of errata corrige? 
Anyway maybe I'm missing something but I see that as a conflict. If I recall
correctly it is stated that the context of a injected friend function must not
be ambiguous, thus meaning you have to declare it first in the correct
namespace. The idea of declaration is that you inform the compiler that the
function exists somewhere so that you can use it without having it defined yet.
If friend function injection is just like defining the function in the parent
namespace of the class and if a template exists as a type (at linking level)
only when you create an instance of that type, it means the moment you
instantiate the template, then the type is defined and consequently the friend
function is injected, thus matching with the declaration done before, thus
matching with the call that used that declaration.
As I pointed in that newsgroup thread, it works fine with normal classes, and
theoretically a template is just a class in the second you create an instance
of it. I don't precisely understand why there should be an exception for
templates. I understand not defining the function if you don't create any
instance of the template, but otherwise it's a bit unclear to me why there
should be this exception. 


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38392


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]