This is the mail archive of the gcc-bugs@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]

PR 764


Hi,
this is about C++ bug 764. The attached test case (derived from
Martin's second test case) produces the following diagnostics,

nathan@uha:21>./g++ -B ./ -c current/764-3.ii 
current/764-3.ii:4: warning: friend declaration `bool operator==(const S<T>&,
   const S<T>&)' declares a non-template function
current/764-3.ii:4: warning: (if this is not what you intended, make sure the 
   function template has already been declared and add <> after the function 
   name here) -Wno-non-template-friend disables this warning.
current/764-3.ii: In function `void foo(S<int>*)':
current/764-3.ii:12: no match for `S<int>& == S<int>&' operator
current/764-3.ii: In function `void baz(S<float>*)':
current/764-3.ii:16: no match for `S<float>& != S<float>&' operator
current/764-3.ii:6: candidates are: bool operator!=(const S<int>&, const 

There's clearly some kind of bug here, something about foo causes S<int>
to be instantiated, but too late to find a match for operator==

I don't understand is why we issue a warning for the declaration
of S<T>::operator==, but not for the definition of S<T>::operator!=.

The relevant bit of the std is 14.5.3, that lists what sort of thing a
friend declaration is. In this case it's neither a template-id nor a
qualified id, therefore the last choice is,
	the name shall be an unqualified id that declares an ordinary
	(non-template) function
but here we've used the template type as parameters, so it's templatized on
something. Shouldn't we issue an error here in both cases?

nathan

-- 
Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
         'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
template<typename T>
struct S
{
  friend bool operator== (const S&, const S&);
  friend bool operator!= (const S&, const S&)
  {
    return true;
  }
};
void foo (S<int> *p)
{
  *p == *p;
}
void baz (S<float> *p)
{
  *p != *p;
}

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