This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/5116: operator resolution in template class
- From: binder at iue dot tuwien dot ac dot at
- To: gcc-gnats at gcc dot gnu dot org
- Cc: hoessinger at iue dot tuwien dot ac dot at
- Date: 14 Dec 2001 15:50:59 -0000
- Subject: c++/5116: operator resolution in template class
- Reply-to: binder at iue dot tuwien dot ac dot at
>Number: 5116
>Category: c++
>Synopsis: operator resolution in template class
>Confidential: no
>Severity: serious
>Priority: high
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Fri Dec 14 07:56:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator: binder@iue.tuwien.ac.at
>Release: 3.0.2
>Organization:
>Environment:
g++ version:
Reading specs from /home/binder2/gcc3/bin/../lib/gcc-lib/i686-pc-linux-gnu/3.0.2/specs
Configured with: ../gcc-3.0.2-src/configure --prefix=/home/binder2/gcc --enable-shared --enable-threads=posix
Thread model: posix
gcc version 3.0.2
OS: RedHat Linux 7.2, kernel 2.4.16
libc version:
GNU C Library stable release version 2.2.4, by Roland McGrath et al.
Copyright (C) 1992-1999, 2000, 2001 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 2.96 20000731 (Red Hat Linux 7.1 2.96-98).
Compiled on a Linux 2.4.9-0.17smp system on 2001-10-03.
Available extensions:
GNU libio by Per Bothner
crypt add-on version 2.1 by Michael Glad and others
The C stubs add-on version 2.1.2.
linuxthreads-0.9 by Xavier Leroy
BIND-8.2.3-T5B
NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk
Glibc-2.0 compatibility add-on by Cristian Gafton
libthread_db work sponsored by Alpha Processor Inc
Report bugs using the `glibcbug' script to <bugs@gnu.org>.
>Description:
In the attached code g++ invokes operator bool() of the template class before the invokation of operator<<() takes place.
This results in printing "1 in operator<<....." to stdout instead of printing "in operator<<..." twice.
#include <iostream>
using namespace std;
template <class T> struct Handle
{
Handle(T* p)
{}
operator bool() const { return true; }
friend ostream& operator<<(ostream& ostr, const Handle& r)
{
return ostr << "in operator<<(ostream&, const Handle&)";
}
};
struct Buggy
{
Buggy()
{}
};
typedef Handle<Buggy> Buggy_h;
struct BuggyCmp
{
bool operator()(const Buggy_h& b1, const Buggy_h& b2) const
{
cout << b1 << " " << b2 << endl;
return false;
}
};
int main()
{
BuggyCmp cmp;
cmp(new Buggy(), new Buggy());
}
>How-To-Repeat:
compile and run the attached program
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="bug1.cc"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="bug1.cc"
CiNpbmNsdWRlIDxpb3N0cmVhbT4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnRlbXBsYXRlIDxjbGFz
cyBUPiBzdHJ1Y3QgSGFuZGxlCnsKCUhhbmRsZShUKiBwKQoJe30KCQoJb3BlcmF0b3IgYm9vbCgp
IGNvbnN0IHsgcmV0dXJuIHRydWU7IH0KCQoJZnJpZW5kIG9zdHJlYW0mIG9wZXJhdG9yPDwob3N0
cmVhbSYgb3N0ciwgY29uc3QgSGFuZGxlJiByKQoJewoJCXJldHVybiBvc3RyIDw8ICJpbiBvcGVy
YXRvcjw8KG9zdHJlYW0mLCBjb25zdCBIYW5kbGUmKSI7Cgl9Cn07CgpzdHJ1Y3QgQnVnZ3kKewoJ
QnVnZ3koKQoJe30KfTsKCnR5cGVkZWYgSGFuZGxlPEJ1Z2d5PglCdWdneV9oOwoKc3RydWN0IEJ1
Z2d5Q21wCnsKCWJvb2wgb3BlcmF0b3IoKShjb25zdCBCdWdneV9oJiBiMSwgY29uc3QgQnVnZ3lf
aCYgYjIpIGNvbnN0Cgl7CgkJY291dCA8PCBiMSA8PCAiICIgPDwgYjIgPDwgZW5kbDsKCQlyZXR1
cm4gZmFsc2U7Cgl9Cn07CgoKaW50IG1haW4oKQp7CglCdWdneUNtcAljbXA7CgoJY21wKG5ldyBC
dWdneSgpLCBuZXcgQnVnZ3koKSk7Cn0KCg==