[Bug c++/46831] [C++0x] Crash when it tries to do an invalid ICS with a conversion function template

schaub.johannes at googlemail dot com gcc-bugzilla@gcc.gnu.org
Tue Dec 7 04:09:00 GMT 2010


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46831

--- Comment #1 from Johannes Schaub <schaub.johannes at googlemail dot com> 2010-12-07 04:09:25 UTC ---
-------------------------------------------------
GCC also rejects this valid code:
----------

struct A { 
  template<typename T = void> operator short(); 
  template<typename T = void> operator long(); 
}; 

void f(long); 
void f(int);

// this call is not ambiguous, but GCC claims it is
int main() { f(A()); }

Also, if we make the second conversion functon a non-template, GCC suddenly
accepts the code (right at it, the code is still valid). 

But that indicates that GCC has internally the handling of
13.3.3[over.match.best]p1 bullet 4 and bullet 5 reversed: It first checks
whether one is a template and the other is a non-template, and only then checks
whether the return type of F1 converts better than the return type of F2. 

--------------------------------------------------
We can make this to crash on valid code, too:
--------

struct B { }; 
struct D : B { }; 
struct A { 
  template<typename T = void> operator D&(); 
  operator long(); 
}; 

void f(long); 
void f(B&);

int main() { f(A()); }



More information about the Gcc-bugs mailing list