Opened 7 years ago

Last modified 2 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 Thierry Delisle)

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 );
} 

Change History (2)

comment:1 Changed 6 years ago by a3moss

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.

comment:2 Changed 2 years ago by Thierry Delisle

Description: modified (diff)

Updated to remove deprecated dtype.

Note: See TracTickets for help on using tickets.