From 4175592356886364642
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,3b5faa9aaea18095,start
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2003-09-20 09:49:07 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!kibo.news.demon.net!mutlu.news.demon.net!demon!mail2news.demon.co.uk!devnull
From: jhrwalter@yahoo.com (Joerg Walter)
Newsgroups: comp.std.c++
Subject: Problem with function template overload resolution
Date: Sat, 20 Sep 2003 16:49:05 +0000 (UTC)
Organization: http://groups.google.com/
Lines: 103
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <4e6fccc6.0309162227.1aa4bda7@posting.google.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: mail2news.demon.co.uk 1064076546 5710 10.0.0.1 (20 Sep 2003 16:49:06 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Sat, 20 Sep 2003 16:49:06 +0000 (UTC)
X-Received: from mulga.cs.mu.oz.au ([128.250.1.22])
	by news.demon.co.uk with esmtp (Exim 4.12)
	id 1A0kuu-0001Tw-00
	for mail2news@news.news.demon.net; Sat, 20 Sep 2003 16:49:05 +0000
X-Received: from localhost (localhost [[UNIX: localhost]]) by mulga.cs.mu.OZ.AU
	id CAA16037; Sun, 21 Sep 2003 02:49:02 +1000 (EST)
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Path: comp-std-cpp-robomod!not-for-mail
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Delivered-To: std-c++@ucar.edu
X-Newsgroups: comp.std.c++
X-NNTP-Posting-Date: 17 Sep 2003 06:27:40 GMT
X-Spam-Status: No, hits=-1.5 required=5.0
	tests=BAYES_01,FORGED_YAHOO_RCVD,HTML_10_20
	version=2.55
X-Spam-Checker-Version: SpamAssassin 2.55 (1.174.2.19-2003-05-19-exp)
Xref: archiver1.google.com comp.std.c++:20826

Hello,

I've already tried to discuss the following two programs on
comp.lang.c++.moderated. Kresimir Fresl's test case

----------
#include <iostream>

template<typename A, typename T>
struct result {};

template<typename T>
struct arg1 {
   typedef T value_type;
};
template<typename T>
struct arg2 {
   typedef T value_type;
};

template<typename A>
result<A, typename A::value_type> foo(A const& a) {
   std::cout << "foo<A>" << std::endl;
   return result<A, typename A::value_type>();
}
template<typename R, typename A>
R foo(A const& a) {
   std::cout << "foo<R, A>" << std::endl;
   return R();
}

int main() {
   arg1<int> s1;
   arg2<int> s2;

   foo(s2);    // OK

   foo<arg1<int>, arg2<int> >(s2);  // OK
   foo<arg2<int>, arg2<int> >(s2);  // OK

   foo<arg1<int> >(s2);    // OK
   foo<arg2<int> >(s2);    // Ambigous?
}

----------

is accepted by GCC 3.3.1, a program run results in

foo<A>
foo<R, A>
foo<R, A>
foo<R, A>
foo<R, A>

ICC 7.1 and MSVC 7.1 reject this code. Patrick Kowalzick's reduced
test case

----------
#include <iostream>

// no basic types to avoid automatic casting
class arg_1 {};
class arg_2 {};

template<typename A> void foo(A const& a)
{
   std::cout << "foo<A>" << std::endl;
}

template<typename R, typename A> void foo(A const& a)
{
   std::cout << "foo<R, A>" << std::endl;
}

int main() {

 foo ( arg_1() );

 foo < arg_1 > ( arg_1() );  // Ambigous?
 foo < arg_2 > ( arg_1() );  // OK

 foo< arg_1 , arg_1 > ( arg_1() );  // OK
 // foo< arg_1 , arg_2 > ( arg_1() );  // no casting from 1 to 2
 foo< arg_2 , arg_1 > ( arg_1() );  // OK
 // foo< arg_2 , arg_2 > ( arg_1() );  // no casting from 1 to 2

}

----------

is accepted by GCC 3.3.1 and ICC 7.1. MSVC 7.1 rejects that code.

Are these legal C++ programs?

Thanks for any enlightenment,
Joerg Walter

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



