Topic: Borland 4.0 template matching problem


Author: stepanov@cello.hpl.hp.com (Alex Stepanov)
Date: Wed, 22 Jun 1994 22:23:13 GMT
Raw View
There seems to be a problem with Borland finding a right template
match. For example, compiling the file "test.cpp":

>
> #include <sdtlib.h>
> int main() {
>  int a[2];
>  return a == max(a, a+1);
> }
>

gets the following error message:

> C:\TURBO>bcc test.cpp
> Borland C++ Version 4.00 Copyright (c) 1993 Borland International
> test.cpp:
> Error test.cpp 4: Could not find a match for 'max(int *, int *)' in function main()
> *** 1 errors in Compile ***
>

Is there a known workaround?

Alex Stepanov

PS this problem came up in relation to some work I am doing for the
C++ standard.






Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Mon, 27 Jun 1994 16:08:07 GMT
Raw View
In article <1994Jun22.222313.25212@cello.hpl.hp.com> stepanov@cello.hpl.hp.com (Alex Stepanov) writes:
>There seems to be a problem with Borland finding a right template
>match.

 No. There seems to a problem with the committee figuring
out what a type is. BC3.1 at least obeyed the ARM to the letter,
and as a consequence function templates were unusable.
This is NOT Borland's fault. The ARM type system is incoherent.
Not surprisingly, that means templates dont work properly.

>For example, compiling the file "test.cpp":
>>
>> #include <sdtlib.h>
>> int main() {
>>  int a[2];
>>  return a == max(a, a+1);
>> }
>>
>
>gets the following error message:
>
>> C:\TURBO>bcc test.cpp
>> Borland C++ Version 4.00 Copyright (c) 1993 Borland International
>> test.cpp:
>> Error test.cpp 4: Could not find a match for 'max(int *, int *)' in function main()
>> *** 1 errors in Compile ***
>>
>Is there a known workaround?

 The function in BC4.0 is declared:

 T const& max(const T&, const T&);

An "exact match" interpretation requires a const T& argument.
Of course, thats ridiculous, in fact there is no expression of
reference type in the WP anymore.  I had this problem
with Borland 3.1 and gave up using function templates.
It got seriously confused, thinking there was some sort of

 'const T'

type. This is plain daft, but the committee thinks such a type exists.
So your problem is you need to pass

 int * const

arguments to the template to match it. In BC3.1 there is a
a work-a-long-way-around:

 int *const& a = a;
 int *const& b = a+1;
 max(a,b);

because now there's an "exact match".

[BTW: I havent tried that particular example]

--
        JOHN (MAX) SKALLER,         INTERNET:maxtal@suphys.physics.su.oz.au
 Maxtal Pty Ltd,      CSERVE:10236.1703
        6 MacKay St ASHFIELD,     Mem: SA IT/9/22,SC22/WG21
        NSW 2131, AUSTRALIA