This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: bug report...


Jason Merrill wrote:

> >   template< class T >
> >   void sort( T* t, int n )
> >   {       struct  { int operator()(T i, T j)
> >                    { return (i < j) ? -1 : ((j < i) ? 1 : 0); }
> >           } c;
> >           sort(t,n,c,0);  
> >   }
> 
> The compiler doesn't give any diagnostic for this testcase because there's
> nothing wrong with it.  It doesn't instantiate any templates using a local
> class; in fact, it doesn't instantiate any templates at all.

Not to be contrary, but that call to sort() looks to me like a template 
function call.  I don't know why it's different from the STL sort, or why
he didn't bother to declare it; an example using the STL version would be 
more like:

  #include <algorithm>
  template< class T >
  void sort( T* t, int n )
  {       struct  { int operator()(T i, T j)
                   { return (i < j); }
          } c;
          std::sort(t,t+n,c);  
  }

and does deserve a warning.

Nathan


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]