------- Additional Comments From mmitchel at gcc dot gnu dot org  2004-12-23 
19:50 -------
The code in the PR is clearly invalid, as it explicitly uses a local class as an
explicit template arugment.  However, the broader question is how to perform
overload resolution when argument deduction has deduced a local class as a
template argument.

The pluasible choices are one of (a) that function being excluded from the set
of overloaded function candidates, (b) an error when deduction is being
performed, or (c) an error only if that function is selected.

GCC presently implements (a), but that means that the set of overloaded
candidates considered changes depending merely on whether or not one of the
function arguments happens to be a local class.  That seems undesirable. 
Furthermore, it's a clear violation of the standard, which lists clearly the
cases in which SFINAE applies; using a local class as an argument is not one of
them.

Here is a test case that distinguishes (a) from the other other choices:

  struct A {};
  A* a;

  void f(A*);
  template <typename T>
  void f(T*);

  void g() {
    f(a); // Calls the non-template function.                                   

    struct B : public A {};
    B* b = 0;

    f(b); // Overload resolution will select f<B*>(B*) if the template          
          // candidate is included in the overload set.  As a local type        
          // cannot be a template argument, that will result in an error        
          // message.  If the template candidate is not included in the         
          // overload set, then the non-template function will be               
          // accepted.                                                          
  }

G++ presently accepts this code.

The previous debate has centered on whether (b) or (c) is a better choice. 
However, I do not think there is an actual difference between (b) or (c).  If
template argument deduction succeeds, overload resolution is guaranteed to find
that function to be a viable function.  So, the only question is whether it will
be the best.  It will be better than any non-template function, because
non-template functions cannot possibly involve local classes as argument types.
 And any template function which was more specialized would also have to involve
the local class in its argument types.  For example, I do not think there is any
other overload of "f" that can be added above that would be selected over the
template version, but which would not also involve a local class type.


-- 


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

Reply via email to