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++/17448] Fails to detect duplicate definition


------- Additional Comments From igodard at pacbell dot net  2004-09-13 15:54 -------
Re #7 from bangaerth -

Yes, this implementation you describe is a source of many of the problems that I (and apparently many others) have been having with friends and templates. You are right, one declares and injects a function template, and the other declares and injects a function of the same name and a particular signature. HOWEVER, when the injected template is later instantiated as a result of a call with the same argument types, the resulting instantiated function has the same name and argument types (i.e. same signature) as the case where a plain function was injected. That is, the function you inject and the instantiation of the injected template are the same.

Unfortunately, the compiler does *not* recognize them as the same, so you get linker error messages for missing functions after "both" get called. I must have 20 places in 5k line of code where "private" is commented out to "public" and "friends" have been moved out of their classes to work around this. It's a real pain. The problem only seems to occur with friend declrations inside templates; for friend definitions (i.e. inline body in the friend) friending works. However, there's a lot of places where you can't use a friend definition, even if code bloat is not an issue: for example, when a function must be a friend of more than one class (and so the function body must appear after the definition of both classes so it can see the private members of each).

I beat my head on this one for weeks. If you have some workaround idiom which by which a function can be a friend *declaration* of two different templates I'd sure like to see it.

Ivan

-- 


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


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