Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug
Bug#: 764
Product:  
Component:  
Status: RESOLVED
Resolution: FIXED
Assigned To: Nathan Sidwell <nathan@gcc.gnu.org>
Host:
Reported against  
Priority:  
Severity:  
Target Milestone:  
 
 
Target:
Reporter: Martin Sebor <msebor@gmail.com>
Add CC:
CC:
Remove selected CCs
Build:
URL:
Summary:
Keywords:
Known to work:
Known to fail:

Attachment Description Type Created Size Actions
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 764 depends on: Show dependency tree
Show dependency graph
Bug 764 blocks:

Additional Comments:






View Bug Activity   |   Format For Printing   |   Clone This Bug


Description:   Last confirmed: Opened: 2000-11-09 19:36
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 From Nathan Sidwell 2000-11-14 08:33 -------
Responsible-Changed-From-To: unassigned->nathan
Responsible-Changed-Why: patch in progress

------- Comment #2 From Nathan Sidwell 2000-11-14 08:33 -------
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 From Martin Sebor 2000-11-14 12:30 -------
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 From Nathan Sidwell 2000-11-14 16:33 -------
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 From Nathan Sidwell 2002-01-02 03:38 -------
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 From Nathan Sidwell 2002-01-02 06:42 -------
State-Changed-From-To: closed->analyzed
State-Changed-Why: oops, I'm not convinced that is correct

------- Comment #7 From Wolfgang Bangerth 2002-11-08 14:48 -------
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 From Nathan Sidwell 2002-12-26 04:27 -------
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.

Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug