Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!APLVAX.JHUAPL.EDU!dan From: dan@APLVAX.JHUAPL.EDU (Daniel M. Sunday) Newsgroups: gnu.gcc.bug Subject: g++ bug report Message-ID: <8907131649.AA05153@aplvax.jhuapl.edu> Date: 13 Jul 89 16:49:44 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 37 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 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"; }