public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: binder@iue.tuwien.ac.at To: gcc-gnats@gcc.gnu.org Cc: hoessinger@iue.tuwien.ac.at Subject: c++/5116: operator resolution in template class Date: Fri, 14 Dec 2001 07:56:00 -0000 [thread overview] Message-ID: <20011214155059.4332.qmail@sources.redhat.com> (raw) >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==
next reply other threads:[~2001-12-14 15:56 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2001-12-14 7:56 binder [this message] 2001-12-30 15:43 nathan 2001-12-31 7:16 nathan 2002-01-02 3:38 nathan 2002-01-02 6:33 nathan 2002-12-26 4:27 nathan
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20011214155059.4332.qmail@sources.redhat.com \ --to=binder@iue.tuwien.ac.at \ --cc=gcc-gnats@gcc.gnu.org \ --cc=hoessinger@iue.tuwien.ac.at \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).