From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30303 invoked by alias); 16 Feb 2007 12:09:43 -0000 Received: (qmail 30272 invoked by uid 48); 16 Feb 2007 12:09:33 -0000 Date: Fri, 16 Feb 2007 12:09:00 -0000 Subject: [Bug c++/30822] New: wrong choice of overloaded template functions in recursive call X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "Zarathustra at gentlemansclub dot de" 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 X-SW-Source: 2007-02/txt/msg01925.txt.bz2 Hello, in the attached piece of code two pairs of template functions are defined which differ just in the order of their definitions. The first pair (for_all_1) is accepted by the compiler (gcc 4.1.1) the second (for_all_2) is rejected. (The aim of the code is to iterate over a list of elements of different types and execute an operation on each element.) The code compiles with the Visual Studio 2005 c++ compiler. gcc 3.3.1 claims that the function calls are ambiguous. I do not have the newest gcc compiler. Could some one please confirm that this is a bug and that it is not fixed with gcc 4.1.2 or later? Thanks Volker #include class element { public: void test() { std::cout << "Hello World" << std::endl; } }; template class op { public: void operator()(TElement elem) { elem.test(); } }; class cons_end { }; template class cons { public: TElement elem; TTail tail; }; // note the order of the definitions of the two functions named for_all_1 template class TOperator,typename TElement> void for_all_1(TElement elem, cons_end tail) { TOperator()(elem); } template class TOperator,typename TElement, typename TTail> void for_all_1(TElement elem, TTail tail) { TOperator()(elem); for_all_1(tail.elem,tail.tail); } // now the order changed and the compiler complains! template class TOperator,typename TElement, typename TTail> void for_all_2(TElement elem, TTail tail) { TOperator()(elem); for_all_2(tail.elem,tail.tail); } template class TOperator,typename TElement> void for_all_2(TElement elem, cons_end tail) { TOperator()(elem); } int main(int argc, char *argv[]) { cons > list; for_all_1(list.elem,list.tail); for_all_2(list.elem,list.tail); } -- Summary: wrong choice of overloaded template functions in recursive call Product: gcc Version: 4.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: Zarathustra at gentlemansclub dot de http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30822