5116 – operator resolution in template class (original) (raw)
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 using namespace std;
template 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_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());}
Release: 3.0.2
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>.
How-To-Repeat: compile and run the attached program
Comment 1 Nathan Sidwell 2001-12-30 15:43:51 UTC
State-Changed-From-To: open->analyzed State-Changed-Why: confirmed
Comment 2 Nathan Sidwell 2001-12-31 07:16:13 UTC
Responsible-Changed-From-To: unassigned->nathan Responsible-Changed-Why: patch in progress
Comment 3 Nathan Sidwell 2002-01-02 03:38:03 UTC
State-Changed-From-To: analyzed->closed State-Changed-Why: 2002-01-02 Nathan Sidwell <nathan@codesourcery.com>
[PR c++/5116](show%5Fbug.cgi?id=5116 "RESOLVED FIXED - operator resolution in template class"), c++/764
* call.c (build_new_op): Make sure template class operands are
instantiated. Simplify arglist construction.Comment 4 Nathan Sidwell 2002-01-02 06:33:13 UTC
State-Changed-From-To: closed->analyzed State-Changed-Why: oops that patch is incorrect.
Comment 5 Nathan Sidwell 2002-12-26 04:27:25 UTC
State-Changed-From-To: analyzed->closed State-Changed-Why: 2002-12-26 Nathan Sidwell <nathan@codesourcery.com>
[PR c++/5116](show%5Fbug.cgi?id=5116 "RESOLVED FIXED - operator resolution in template class"), c++/764
* call.c (build_new_op): Make sure template class operands are
instantiated.