From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9168 invoked by alias); 14 Dec 2001 15:56:01 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 9137 invoked by uid 71); 14 Dec 2001 15:56:00 -0000 Resent-Date: 14 Dec 2001 15:56:00 -0000 Resent-Message-ID: <20011214155600.9136.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-To: nobody@gcc.gnu.org Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org, hoessinger@iue.tuwien.ac.at Resent-Reply-To: gcc-gnats@gcc.gnu.org, binder@iue.tuwien.ac.at Received:(qmail 4333 invoked by uid 61); 14 Dec 2001 15:50:59 -0000 Message-Id:<20011214155059.4332.qmail@sources.redhat.com> Date: Fri, 14 Dec 2001 07:56:00 -0000 From: binder@iue.tuwien.ac.at Reply-To: binder@iue.tuwien.ac.at To: gcc-gnats@gcc.gnu.org Cc: hoessinger@iue.tuwien.ac.at X-Send-Pr-Version:gnatsweb-2.9.2 (1.1.1.1.2.21) X-GNATS-Notify:hoessinger@iue.tuwien.ac.at Subject: c++/5116: operator resolution in template class X-SW-Source: 2001-12/txt/msg00826.txt.bz2 List-Id: >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 . >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 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()); } >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==