[gnu.gcc.bug] g++ bug report

dan@APLVAX.JHUAPL.EDU (Daniel M. Sunday) (07/13/89)

I discovered the following bug while working with g++.
The Overloaded Function Selection Algorithm is in 3 steps:

1.  Use an exact match if found.
2.  Try implicit standard type conversions and use any match.
    THESE CONVERSIONS MUST NOT LOSE INFORMATION.
3.  Try user-defined conversions, and use a unique match.

Unfortunately, g++ (which is an excellant compiler - one of the finest
I have ever used) does not enforce the bold faced part of condition 2.
This part of the condition is a bit hidden in Bjarne's C++, but is
clearly stated in Section 4.6.7 in the first paragraph on page 123.

Here is an easy example (from Pohl's C++) of the bug.
The double version of greater should be called in this example,
but g++ decides to use the first defined int version of it.

				dan sunday
				dan@aplvax.jhuapl.edu


# include <stream.h>

overload greater;
inline int	greater( int i, int j )
		{ return (i > j ? i : j); }
inline double	greater( double x, double y )
		{ return (x > y ? x : y); }


main()
{
	int	i = 5;
	double	x = 14.5;

	cout << greater( i, x) << "\n";
}