c++/1007: Bogus error message resolving overloaded operators
Peter.Bienstman@rug.ac.be
Peter.Bienstman@rug.ac.be
Thu Dec 7 06:56:00 GMT 2000
>Number: 1007
>Category: c++
>Synopsis: Bogus error message resolving overloaded operators
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Dec 07 06:56:00 PST 2000
>Closed-Date:
>Last-Modified:
>Originator: Peter Bienstman
>Release: GCC 2.97 20001128
>Organization:
>Environment:
i686-pc-linux-gnu
>Description:
When compiling the attached incorrect source file, g++ gives the following bogus error:
/tmp/@22251.7.cc: In function `void f(Complex*)':
/tmp/@22251.7.cc:28: no match for `std::complex& = Coord' operator
/usr/local/include/g++-v3/bits/std_complex.h:681: candidates are:
std::complex& std::complex::operator=(double)
/usr/local/include/g++-v3/bits/std_complex.h:662:
std::complex& std::complex::operator=(const std::complex&)
Of course, the class Coord should not be involved in this. Removing the inline Coord operator* operator gives the correct error:
/tmp/@22315.7.cc: In function `void f(Complex*)':
/tmp/@22315.7.cc:27: no match for `int& * Complex&' operator
>How-To-Repeat:
Compile this source file:
#include <complex>
using namespace std;
typedef complex<double> Complex;
class Coord
{
public:
Coord(const Complex& x_ = 0.0,
const Complex& y_ = 0.0,
const Complex& z_ = 0.0)
: x(x_), y(y_), z(z_) {}
Complex x;
Complex y;
Complex z;
};
inline Coord operator*(const Complex& c, const Coord& co) {return co;}
void f(Complex* R)
{
Complex a(1,0);
int sign = 1;
*R = sign * a;
}
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-prs
mailing list