764 – friend operator and dereferencing a pointer and templates (original) (raw)
| Description Martin Sebor 2000-11-09 19:36:01 UTC The compiler fails to find the (non-template) friend operator defined in a template class when it is applied to an object obtained by dereferencing a pointer. When the friend is a template, the problem disappears. The same error occurs in gcc-20001002. Release: 2.95.2, gcc-20001002 How-To-Repeat: template struct S { friend bool operator== (const S&, const S&) { return true; } }; int main () { S s; s == s; // okay const S *p = &s; *s == *s; // error } Comment 1 Nathan Sidwell 2000-11-14 08:33:31 UTC Responsible-Changed-From-To: unassigned->nathan Responsible-Changed-Why: patch in progress Comment 2 Nathan Sidwell 2000-11-14 08:33:31 UTC State-Changed-From-To: open->analyzed State-Changed-Why: this is user error, but the diagnostic is rather blunt, and confusing. you mean "*p == *p"! Comment 3 Martin Sebor 2000-11-14 12:30:50 UTC From: Martin Sebor <sebor@roguewave.com> To: Cc: gcc bug reports <gcc-bugs@gcc.gnu.org>, gcc-gnats@gcc.gnu.org Subject: Re: c++/764 Date: Tue, 14 Nov 2000 12:30:50 -0700 nathan@gcc.gnu.org wrote: > > The following reply was made to PR c++/764; it has been noted by GNATS. > > From: nathan@gcc.gnu.org > To: gcc-gnats@gcc.gnu.org, nathan@gcc.gnu.org, nobody@gcc.gnu.org, > sebor@roguewave.com > Cc: > Subject: Re: c++/764 > Date: 14 Nov 2000 16:33:31 -0000 > > Synopsis: g++ 2.95.2 fails to find a friend operator when dereferencing a pointer > > Responsible-Changed-From-To: unassigned->nathan > Responsible-Changed-By: nathan > Responsible-Changed-When: Tue Nov 14 08:33:31 2000 > Responsible-Changed-Why: > patch in progress > State-Changed-From-To: open->analyzed > State-Changed-By: nathan > State-Changed-When: Tue Nov 14 08:33:31 2000 > State-Changed-Why: > this is user error, but the diagnostic is rather blunt, > and confusing. > > you mean "*p == *p"! > > http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=764&database=gcc Sorry, the typo was my mistake (caused by reducing the size of the code). The original test case also hides the bug, so here's a new testcase that reproduces it. Uncommenting the definition of `s' in main eliminates the problem. Regards Martin template struct S { friend bool operator== (const S&, const S&) { return true; } }; int main () { // S s; const S *p = 0; *p == *p; // error } $ g++ test.cpp -c test.cpp: In function `int main()': test.cpp:33: no match for `const S & == const S &' Comment 5 Nathan Sidwell 2002-01-02 03:38:30 UTC State-Changed-From-To: analyzed->closed State-Changed-Why: 2002-01-02 Nathan Sidwell <nathan@codesourcery.com> PR c++/5116, c++/764 * call.c (build_new_op): Make sure template class operands are instantiated. Simplify arglist construction. Comment 6 Nathan Sidwell 2002-01-02 06:42:06 UTC State-Changed-From-To: closed->analyzed State-Changed-Why: oops, I'm not convinced that is correct Comment 8 Nathan Sidwell 2002-12-26 04:27:46 UTC State-Changed-From-To: analyzed->closed State-Changed-Why: 2002-12-26 Nathan Sidwell <nathan@codesourcery.com> PR c++/5116, c++/764 * call.c (build_new_op): Make sure template class operands are instantiated. | | | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |