This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/12433] Finds wrong overload of std::operator<<
- From: "igodard at pacbell dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 28 Sep 2003 15:46:10 -0000
- Subject: [Bug c++/12433] Finds wrong overload of std::operator<<
- References: <20030927205755.12433.igodard@pacbell.net>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12433
igodard at pacbell dot net changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
------- Additional Comments From igodard at pacbell dot net 2003-09-28 15:46 -------
Nope; there is something funny about std::operator <<, and it is not something that is generic to function pointers. Here's a demonstration test case:
#include <iostream>
using namespace std;
class S {};
S ss;
S* s = &ss;
void Tst(const char* id, bool b) { cout << id << " bound to bool" << endl; }
template<typename T>
void Tst(const char* id, T* t) { cout << id << " bound to pointer" << endl;}
int (*Foo)() = 0;
int Bar() { return 0; }
int main() {
float ff;
float* f = &ff;
cout << "f:" << f << endl;
cout << "s:" << s << endl;
cout << "Bar:" << Bar << endl;
cout << "*Bar:" << *Bar << endl;
cout << "Foo:" << Foo << endl;
cout << "*Foo:" << *Foo << endl;
Tst("Bar", Bar);
Tst("Foo", Foo);
Tst("*Bar", *Bar);
Tst("*Foo", *Foo);
return 0; }
**********************************************
When you compile this you get the convert to bool warnings. When you run this, you get:
f:0xbffffd34
s:0x8049dc1
Bar:1
*Bar:1
Foo:0
*Foo:0
Bar bound to pointer
Foo bound to pointer
*Bar bound to pointer
*Foo bound to pointer
***********************************************
So my template Tst happily accepts function pointers (and data pointers) - but std:operator<< converts function pointers (but not data pointers) to bool. I don't think this is intentional; it is certainly useless. In fact, I can't think of a template you could write that would distinguish a data from a function pointer if you wanted to - would
template<typename T>
void CatchFunc(T (*p)(...));
work? Can the compiler convert any function to the ellipsis form?
I don't know if this is a compiler problem or a library issue; if the latter please pass it on to whoever is relevant.
Ivan