This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
possible bug in gcc 3.2.1
- From: Robert Ramey <ramey at rrsd dot com>
- To: "'gcc-bugs at gcc dot gnu dot org'" <gcc-bugs at gcc dot gnu dot org>
- Date: Mon, 18 Aug 2003 13:46:04 -0700
- Subject: possible bug in gcc 3.2.1
Gentlemen,
I believe the example below illustrates a bug on gcc version 3.2.1.
Then again maybe not. I don't see anything wrong with passing
a temporary object by reference. In this case it is used as a
wrapper for references to the "real" objects. So it is in fact
what I want to do.
If it is an error, the error message doesn't help much. It took
me an incredibly long time to isolate this example from my
own large project.
Thanks in advance.
Robert Ramey
// followin illustrates issue with gcc version 3.2.1
class A
{
};
template<class T>
struct nvp
{
T t;
nvp(const char *name, T t_)
: t(t_)
{}
};
class test_class
{
public:
template<class T>
test_class & operator>>(T & t)
{
// snip ...
return *this;
}
// note: if the argument is passed by value rather than
// by reference, compile never fails.
//template<class T>
//test_class & operator>>(T t)
//{
// return *this;
//}
};
int main( int argc, char* argv[] )
{
test_class ia;
A a;
ia >> a;
int i;
ia >> i;
nvp<A> x("a", a);
ia >> x; // this compiles
nvp<A> & xref = x;
ia >> xref; // this compiles
ia >> nvp<A>("a", a); // this fails to compile!!!
return 0;
}
/*
c:/boost-dev/libs/serialization/test/test_gcc.cpp: In function `int main(int,
char**)':
c:/boost-dev/libs/serialization/test/test_gcc.cpp:53: no match for `test_class&
>> nvp<A>' operator
c:/boost-dev/libs/serialization/test/test_gcc.cpp:22: candidates are:
test_class& test_class::operator>>(T&) [with T = nvp<A>]
*/