Bug 764 - friend operator and dereferencing a pointer and templates
Summary: friend operator and dereferencing a pointer and templates
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 2.95.2
: P3 normal
Target Milestone: ---
Assignee: Nathan Sidwell
URL:
Keywords:
: 807 (view as bug list)
Depends on:
Blocks:
 
Reported: 2000-11-09 19:36 UTC by Martin Sebor
Modified: 2003-07-25 17:33 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 <class T>
struct S
{
    friend bool operator== (const S&, const S&) {
        return true;
    }
};

int main ()
{
    S<int> s;
    s == s;   // okay

    const S<int> *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 <class T>
 struct S
 {
     friend bool operator== (const S&, const S&) {
         return true;
     }
 };
 
 int main ()
 {
     // S<int> s;
 
     const S<int> *p = 0;
     *p == *p; // error
 }
 
 $ g++ test.cpp -c
 test.cpp: In function `int main()':
 test.cpp:33: no match for `const S<int> & == const S<int> &'
Comment 4 Nathan Sidwell 2000-11-14 16:33:31 UTC
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

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 7 Wolfgang Bangerth 2002-11-08 14:48:55 UTC
From: Wolfgang Bangerth <bangerth@ticam.utexas.edu>
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: Re: c++/764: g++ 2.95.2 fails to find a friend operator when
 dereferencing a pointer
Date: Fri, 8 Nov 2002 14:48:55 -0600 (CST)

 This still exists, even with 3.3 CVS. The normative clause in the standard 
 is probably 14.5.3.3.
 
 W.
 
 -------------------------------------------------------------------------
 Wolfgang Bangerth              email:           bangerth@ticam.utexas.edu
                                www: http://www.ticam.utexas.edu/~bangerth
 
 
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.