Consider this code: -------------------- #include <iostream> struct null { null() {} template<class T> operator T*() const { return 0; }
template<class C, class T> operator T C::*() const { return 0; } private: null(const null&); null& operator=(const null&); void operator&() const; }; static struct null null; int main() { int* ptr = null; std::cout << (ptr == null) << ", " << (ptr != null); return 0; } -------------------------------- This compiles and gives the expected output ("true, false") on the following platforms: http://codepad.org (GCC 4.1, Linux) Ubuntu 9.10, GCC 4.3 Ubuntu 10.04, GCC 4.4 Mac OS X 10.6, GCC 4.2 Mac OS X 10.6, GCC 4.4 Cygwin, GCC 4.3 Cygwin, GCC 4.4 Unknown Linux variant, Clang 2.8 (trunk 111679) (the "clang" bot on irc.freenode.net) However, I get following error on these platforms ------------- error: no match for 'operator==' in 'ptr == null' ------------- Cygwin, GCC 4.5 Ubuntu 10.04, GCC 4.5 Unknown Linux variant, GCC 4.6.0 20100507 (the "geordi" bot on irc.freenode.net) The people in the irc.freenode.net/##c++ channel confirm that this is indeed valid C++ code and therefore a bug in GCC. I do not have ready access to some of these systems (anymore), so I can not say with certainity what their host, target, or build triplets are. -- Summary: [g++ >= 4.5 ] Implicit conversion to pointer does no longer automatically generate operator== and operator!=. Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: seysayux at gmail dot com GCC build triplet: (many, read below) GCC host triplet: (many, read below) GCC target triplet: (many, read below) http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45383