Opened 8 years ago
Last modified 3 years ago
#82 assigned defect
Wrong Overload Chosen
| Reported by: | Rob Schluntz | Owned by: | a3moss |
|---|---|---|---|
| Priority: | minor | Component: | cfa-cc |
| Version: | 1.0 | Keywords: | resolver overload polymorphism |
| Cc: |
Description (last modified by )
The following example currently chooses the signed ?-?, but should choose unsigned ?-?. I believe it’s getting there because it delays the conversion cost for arguments until getting to bsearch, so by this point signed ?-? and unsigned ?-? are still both candidates, and unsigned ?-? fails because E is bound to unsigned and signed */unsigned * do not unify.
forall( E ) void bsearch( E key, const E * vals );
signed int ?-?( signed int, signed int );
unsigned int ?-?( unsigned int, unsigned int );
void f() {
int iarr[10];
bsearch( (unsigned int)10 - (unsigned int)0, iarr );
}
If you take the polymorphism away, the unsigned ?-? is chosen.
void bsearch( signed int key, const signed int * vals ); // chosen
void bsearch( unsigned key, const unsigned int * vals );
signed int ?-?( signed int, signed int );
unsigned int ?-?( unsigned int, unsigned int ); // chosen
void f() {
int iarr[10];
bsearch( (unsigned int)10 - (unsigned int)0, iarr );
}
Note:
See TracTickets
for help on using tickets.
A related case that fails to resolve, because the missing
?-?removes the scope for type conversion:forall(otype E | {int ?<?(E, E);}) E* bsearch( E key, const E* vals, size_t dim ); forall( otype K, otype E | {int ?<?(K, K); K getKey(const E&);}) E* bsearch( K key, const E* vals, size_t dim ); int main() { const unsigned int size = 10; unsigned int i = 0u; int iarr[size]; int* v = bsearch( i, iarr, size ); }These all work properly in the resolver prototype.