the following testcase from KDE source can not be compiled with gcc 4.1 or newer: === Cut === int qHash(char key); int qHash(int key); template <class Key> struct QHash { void findNode(const Key &key) { qHash(key); } }; namespace khtml { struct Font { struct ScalKey { }; }; } int qHash (const khtml::Font::ScalKey& key); static QHash<khtml::Font::ScalKey>* scalCache; void isFontScalable() { khtml::Font::ScalKey key; scalCache->findNode(key); } === Cut === font-testcase.cpp: In member function ‘void QHash<Key>::findNode(const Key&) [with Key = khtml::Font::ScalKey]’: font-testcase.cpp:29: instantiated from here font-testcase.cpp:6: error: no matching function for call to ‘qHash(const khtml::Font::ScalKey&)’ font-testcase.cpp:1: note: candidates are: int qHash(char) font-testcase.cpp:2: note: int qHash(int)
The issue here (in the source) is that the overloaded of " qHash(key);" is only the qHash functions above that call so it does not see the template below that call which is the function you would like to call. This is how standard C++ works (with the correction from DR 197). This is a dup of bug 2922 which was fixed by rejecting invalid code and fixing wrong code for 4.1. The way to fix the code is to add a forward to the template function. *** This bug has been marked as a duplicate of 2922 *** *** This bug has been marked as a duplicate of 2922 ***
how do you explain that the testcase compiles just fine if you remove the namespace?
(In reply to comment #2) > how do you explain that the testcase compiles just fine if you remove the > namespace? Because Agrument Dependent Lookup (koenig lookup) happens even though there is an overloaded set. This is also referenced in that PR. If you move qHash of khtml::Font::ScalKey into the khtml, it will work also because ADL is happening.
Please read the Defect report which takes about this case: http://www.open-std.org/jtc1/sc22/wg21/prot/14882fdis/cwg_defects.html#197