public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "bangerth at dealii dot org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/30822] wrong choice of overloaded template functions in recursive call Date: Fri, 09 Mar 2007 04:14:00 -0000 [thread overview] Message-ID: <20070309041429.24666.qmail@sourceware.org> (raw) In-Reply-To: <bug-30822-14112@http.gcc.gnu.org/bugzilla/> ------- Comment #5 from bangerth at dealii dot org 2007-03-09 04:14 ------- Here's a reduced code: ----------------- struct cons_end {}; template<typename U,typename V> struct cons { U elem; V tail; }; template<class T,typename U, typename V> void foo(U elem, V tail) { foo<T>(tail.elem,tail.tail); } template<class T,typename U> void foo(U elem, cons_end tail) {} int main() { cons<int,cons<int,cons_end> > list; foo<int>(list.elem,list.tail); } -------------------- With gcc3.3, we get this error: tmp/g> c++ -c x.cc x.cc: In function `void foo(U, V) [with T = int, U = int, V = cons<int, cons_end>]': x.cc:21: instantiated from here x.cc:11: error: call of overloaded `foo(int&, cons_end&)' is ambiguous x.cc:10: error: candidates are: void foo(U, V) [with T = int, U = int, V = cons_end] x.cc:16: error: void foo(U, cons_end) [with T = int, U = int] On the other hand, gcc 4.1 produces this: g/x> c++ -c x.cc x.cc: In function 'void foo(U, V) [with T = int, U = int, V = cons_end]': x.cc:11: instantiated from 'void foo(U, V) [with T = int, U = int, V = cons<int, cons_end>]' x.cc:21: instantiated from here x.cc:11: error: 'struct cons_end' has no member named 'elem' x.cc:11: error: 'struct cons_end' has no member named 'tail' Finally, icc gives me this: tmp/g> icc -c x.cc x.cc(21): warning #592: variable "list" is used before its value is set foo<int>(list.elem,list.tail); ^ x.cc(11): error: more than one instance of overloaded function "foo" matches the argument list: function template "foo<T,U,V>(U, V)" function template "foo<T,U>(U, cons_end)" argument types are: (int, cons_end) foo<T>(tail.elem,tail.tail); ^ detected during instantiation of "void foo<T,U,V>(U, V) [with T=int, U=int, V=cons<int, cons_end>]" compilation aborted for x.cc (code 2) So, the way I read this is that gcc3.3 and icc9.0 agree that the call is ambiguous. I must admit that I don't know whether this is the correct behavior. On the other hand, gcc4.1 appears to not find an ambiguity, then goes on to unconditionally call the first function and there hits onto a problem. W. -- bangerth at dealii dot org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bangerth at dealii dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30822
next prev parent reply other threads:[~2007-03-09 4:14 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2007-02-16 12:09 [Bug c++/30822] New: " Zarathustra at gentlemansclub dot de 2007-02-16 15:47 ` [Bug c++/30822] " pinskia at gcc dot gnu dot org 2007-02-16 16:35 ` Zarathustra at gentlemansclub dot de 2007-02-21 7:44 ` Zarathustra at gentlemansclub dot de 2007-02-21 10:16 ` Zarathustra at gentlemansclub dot de 2007-03-09 4:14 ` bangerth at dealii dot org [this message] 2007-03-09 12:36 ` Zarathustra at gentlemansclub dot de 2007-05-17 12:27 ` Zarathustra at gentlemansclub dot de
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20070309041429.24666.qmail@sourceware.org \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).