public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* Re: g++; operator==
@ 2005-08-30 8:17 Richard Guenther
0 siblings, 0 replies; 2+ messages in thread
From: Richard Guenther @ 2005-08-30 8:17 UTC (permalink / raw)
To: Markus Bina; +Cc: gcc-bugs
First of all, this mailinglist only tracks bugzilla
(http://gcc.gnu.org/bugzilla) activity, so getting help
this way is going to fail.
Second, your testcase is invalid C++, to fix it, change
operator== to
bool operator== (const Int& i2) const {
return (this->i == i2.i ? true : false);
}
as you cannot bind a temporary (which Int(2) is) to an
lvalue reference.
Your other compilers are wrong in accepting the code.
Richard.
^ permalink raw reply [flat|nested] 2+ messages in thread
* g++; operator==
@ 2005-08-30 8:09 Markus Bina
0 siblings, 0 replies; 2+ messages in thread
From: Markus Bina @ 2005-08-30 8:09 UTC (permalink / raw)
To: gcc-bugs
Hi!
g++ Version: 3.3.5
Linux-distribution: Suse 9.2 and Gentoo 2005.0 on Intel Pentium 4
CFLAGS used to compile gcc: -O2 -pipe
I found the following bug:
bash-output:
xyz@linux:~/test> g++ -o Prog.bin Prog.cpp
Prog.cpp: In function `int main()':
Prog.cpp:32: error: no match for 'operator==' in 'i1 == Int(2)'
Prog.cpp:18: error: candidates are: bool Int::operator==(Int&)
xyz@linux:~/test>
BTW: VC++ and TurboC are able to compile it!
--------------------------------------------------------------------
It is far too difficult to describe the bug, so here is a code snippet to
reproduce the bug:
#include <iostream>
using namespace std;
class Int{
public:
int i;
Int(){
this->i = 0;
}
Int(int i2){
this->i = i2;
}
Int& operator= (Int& i2){
this->i = i2.i;
return *this;
}
bool operator== (Int& i2){
return (this->i == i2.i ? true : false);
}
};
int main(){
Int i1(10);
Int i2(20);
// works
cout << (i1 == i2) << endl;
// does not work; but it should
cout << (i1 == Int(2)) << endl;
return 0;
}
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-08-30 8:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-30 8:17 g++; operator== Richard Guenther
-- strict thread matches above, loose matches on Subject: below --
2005-08-30 8:09 Markus Bina
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).