Bug 764 - friend operator and dereferencing a pointer and templates
|
Bug#:
764
|
Product: gcc
|
Version: 2.95.2
|
|
Host:
|
Target:
|
Build:
|
|
Status: RESOLVED
|
Severity: normal
|
Priority: P3
|
|
Resolution: FIXED
|
Assigned To: nathan@gcc.gnu.org
|
Reported By: msebor@gmail.com
|
|
Component: c++
|
Target Milestone: ---
|
|
Summary: friend operator and dereferencing a pointer and templates
|
|
Keywords:
|
|
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
}
Responsible-Changed-From-To: unassigned->nathan
Responsible-Changed-Why: patch in progress
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"!
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> &'
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.
State-Changed-From-To: closed->analyzed
State-Changed-Why: oops, I'm not convinced that is correct
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.