From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21244 invoked by alias); 28 Mar 2013 08:27:41 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 21223 invoked by uid 48); 28 Mar 2013 08:27:34 -0000 From: "erik.thiele@thiele-hydraulik.de" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/56760] namespaces, templates and forwarding declarations. Date: Thu, 28 Mar 2013 08:27:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: erik.thiele@thiele-hydraulik.de X-Bugzilla-Status: RESOLVED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 X-SW-Source: 2013-03/txt/msg02074.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56760 --- Comment #6 from erik.thiele@thiele-hydraulik.de 2013-03-28 08:27:34 UTC --- let me paste "v3 source code" that is also added as attachment: namespace nam { class binbuffer {}; } template void func (const T &a, nam::binbuffer &b); namespace seco { template struct holder { X *fun; }; template struct contain { T *wombat; }; } template void func(const seco::contain &a, nam::binbuffer &b) { func(*a.wombat, b); } template void func(const seco::holder &a, nam::binbuffer &b) { func(*a.fun, b); } template<> void func(const int &a, nam::binbuffer &b) {} int main() { nam::binbuffer b; seco::holder foo; func(foo, b); seco::contain > containHolder; func(containHolder, b); // COMMENT THIS OUT AND IT WORKS return 0; } END OF CODE when you compile this, it sais g++ -Wall v3.cpp /tmp/ccDElJvq.o: In function `void func >(seco::contain > const&, nam::binbuffer&)': v3.cpp:(.text._Z4funcIN4seco6holderIiEEEvRKNS0_7containIT_EERN3nam9binbufferE[_Z4funcIN4seco6holderIiEEEvRKNS0_7containIT_EERN3nam9binbufferE]+0x16): undefined reference to `void func >(seco::holder const&, nam::binbuffer&)' collect2: error: ld returned 1 exit status but when you comment out the line "COMMENT THIS OUT AND IT WORKS" then it compiles. now consider the line "func(foo, b)". here exactly the function gets called that the linker sais is not defined. How can the linker say the function is not defined, even though it obviously is defined? you can make it even more clear: comment out this: //template void func(const seco::holder &a, nam::binbuffer &b) //{ func(*a.fun, b); } but reenable the line "COMMENT THIS OUT AND IT WORKS" then you get this output: g++ -Wall v3.cpp /tmp/cc3keqh3.o: In function `main': v3.cpp:(.text+0x1e): undefined reference to `void func >(seco::holder const&, nam::binbuffer&)' /tmp/cc3keqh3.o: In function `void func >(seco::contain > const&, nam::binbuffer&)': v3.cpp:(.text._Z4funcIN4seco6holderIiEEEvRKNS0_7containIT_EERN3nam9binbufferE[_Z4funcIN4seco6holderIiEEEvRKNS0_7containIT_EERN3nam9binbufferE]+0x16): undefined reference to `void func >(seco::holder const&, nam::binbuffer&)' collect2: error: ld returned 1 exit status you see, it sais two times that the function is not defined. that's OK! now if you reenable: template void func(const seco::holder &a, nam::binbuffer &b) { func(*a.fun, b); } then only the second error message keeps being there. but it misses exactly the same function! what's going on here? the function is there and it gets called once. why cannot it get called twice???