This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Apparant C++ bug in gcc 2.95.2 and latest egcs snapshot
- To: gcc-bugs at gcc dot gnu dot org
- Subject: Apparant C++ bug in gcc 2.95.2 and latest egcs snapshot
- From: Nicholas Vinen <hb at fl dot net dot au>
- Date: Fri, 17 Mar 2000 19:04:17 +1100 (EST)
OK, code is included. If this isn't a bug, it's definately
strange.
Compile the program. It compiles fine.
Now try compiling with -fno-default-inline. It compiles but fails
to link. If you add "inline" to that friend operator definition on line
50, it works.
It seems to me, it shouldn't matter if a function is declared
inline or not whether the code links... I don't know why the person that
wrote this code declared the operator that way but it seems to work under
all circumstances but this with this and other compilers. For now I'll
declare it inline, hopefully you can work out why it's doing this so I
don't have to.
Nicholas Vinen
---
"... one of the main causes of the fall of the Roman Empire was that,
lacking zero, they had no way to indicate successful termination of
their C programs."
-- Robert Firth
template <class TYPE>
class TPoint
{
public:
TPoint(TYPE x, TYPE y)
{
this->x = x;
this->y = y;
}
TYPE x, y;
TPoint<TYPE> operator-() const { TPoint<TYPE> tReturn(-x,-y); return tReturn; };
};
template <class TYPE>
class TRect
{
public:
TRect()
{
}
TRect(TYPE left, TYPE top, TYPE right, TYPE bottom)
{
this->left = left;
this->top = top;
this->right = right;
this->bottom = bottom;
}
TYPE left, top, right, bottom;
TPoint<TYPE> UpperLeft() const { return TPoint<TYPE>(left, top); };
template <class OTHERTYPE>
void Translate( OTHERTYPE x, OTHERTYPE y )
{
left += (TYPE)x;
right += (TYPE)x;
top += (TYPE)y;
bottom += (TYPE)y;
}
template <class OTHERTYPE>
void Translate(const TPoint<OTHERTYPE> pt)
{
Translate(pt.x, pt.y);
}
friend TRect<TYPE> operator-( const TRect<TYPE>& rc, const TPoint<TYPE>& pt ){ TRect<TYPE> trc(rc); trc.Translate(-pt); return trc; };
__inline TRect AreaRect() const
{
return *this - UpperLeft();
}
};
int main(void)
{
TRect<int> a(0,0,10,10);
TRect<int> area;
area = a.AreaRect();
return 0;
}