From 5143034314125774971
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,da46f9d6feb862e5
X-Google-Attributes: gidf78e5,public
From: James.Kanze@dresdner-bank.com
Subject: Re: Is this well-formed?
Date: 1999/04/19
Message-ID: <7ffmrv$j09$1@nnrp1.dejanews.com>#1/1
X-Deja-AN: 468366380
Approved: Valentin Bonnard <bonnard@clipper.ens.fr>
References: <7f1nnv$6c$1@weber.techno-link.com>
X-Original-Date: Mon, 19 Apr 1999 16:50:11 GMT
X-Http-User-Agent: Mozilla/4.5 [en] (WinNT; I)
X-Http-Proxy: 1.0 x7.dejanews.com:80 (Squid/1.1.22) for client 193.194.7.71
Organization: Deja News - The Leader in Internet Discussion
X-Article-Creation-Date: Mon Apr 19 16:50:11 1999 GMT
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUANxtfoqwEuYhIxRhxAQGx4AH9GvsuP/bSHJRhaWJgZUoS51TbIUJkcO4Z uEPH2ur/rVX/wWBmbAkT3WZV926sDun1v4SRqSXpx358PxJ51g2SBA== =J5Xq
Newsgroups: comp.std.c++

$1@weber.techno-link.com>,
  "Peter Dimov" <pdimov@techno-link.com> wrote:
> Is the following program well-formed?
>
> template<class U> void f(U*)
> {
> }
>
> void f(int*)
> {
> }
>
> int main()
> {
>  f(0);
>  return 0;
> }

I think so.

> Note: MSVC6SP2 rejects it:
>
> error C2784: 'void __cdecl f(U *)' : could not deduce template argument for
> ' *' from 'const int'

According to 13.3.3., a non-template function is a better match than a
template function, so the non template f(int*) should be preferred.  I
suspect that Microsoft is trying to instantiate the template in order to
create the list of all viable functions, and failing, because there are
an infinite number of instantiations which could work.

I don't think Microsoft is the only compiler to have this error.  If you
think about it, it isn't simple; if an instantiation of the template
were to give f(int), this would be preferred over the non-template
function.  (I also have vague memories that at one time, if a
non-template function could be called, template functions weren't even
considered.  But I could be wrong about that.)

--
James Kanze                         mailto: James.Kanze@dresdner-bank.com
Conseils en informatique orientie objet/
                        Beratung in objekt orientierter Datenverarbeitung
Ziegelh|ttenweg 17a, 60598 Frankfurt, Germany  Tel. +49 (069) 63 19 86 27

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]



