From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12845 invoked by alias); 24 May 2004 15:19:36 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 12709 invoked by uid 48); 24 May 2004 15:19:32 -0000 Date: Tue, 25 May 2004 12:50:00 -0000 Message-ID: <20040524151932.12708.qmail@sourceware.org> From: "bangerth at dealii dot org" To: gcc-bugs@gcc.gnu.org In-Reply-To: <20040524081805.15629.ywhu@nmi.iii.org.tw> References: <20040524081805.15629.ywhu@nmi.iii.org.tw> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug c++/15629] Function templates, overloads, and friend name injection X-Bugzilla-Reason: CC X-SW-Source: 2004-05/txt/msg02772.txt.bz2 List-Id: ------- Additional Comments From bangerth at dealii dot org 2004-05-24 15:19 ------- OK, something is really screwed up here. Take this: ----------------- #include #define PRINT std::cerr << __PRETTY_FUNCTION__ << std::endl template class T; template void func(T * t) { PRINT; } template void func(T * t) { PRINT; } template struct T { friend void func(T * t); friend void func (T * t); void foo(); }; template void T::foo() { func((T<2,3>*)0); } int main() { func((T<2,3>*)0); T<2,3>().foo(); } ----------------------- Note that the call to func in main() is the same as the one in foo(), so it should really yield the same result. Alas, with gcc3.4, we get: g/x> /home/bangerth/bin/gcc-3.4-pre/bin/c++ x.cc ; ./a.out void func(T*) [with int a = 2] void func(T*) [with int a = 2, int b = 3] On the other hand, if we revert the order of the two calls in main(), we get a different result, namely a call to the general T template as in the second line above. My inclination is to say that this is due to the fact that we only instantiate T<2,3> in the second call in main(), since the cast to (T<2,3>*)0 does not require instantiation of the template. Now, how that can affect the result I don't know -- presumably it has something to do with injecting the friend functions into the global namespace. This explains why reverting the calls in main() changes the result. What evades me, however, is why injecting the names should make any difference? Note that if I remove the friend declarations altogether, then we get two calls to the template, irrespective of the call order in main(). I tend to think that this is what we should get in all cases, but would like to have a second opinion... W. -- What |Removed |Added ---------------------------------------------------------------------------- Summary|Function overloading doesn't|Function templates, |happen when I use friend |overloads, and friend name |function templates in class |injection |templates. | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15629