Bug 26311 - [4.1/4.2 Regression] ambiguous overload errors
Summary: [4.1/4.2 Regression] ambiguous overload errors
Status: RESOLVED DUPLICATE of bug 2922
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-16 00:27 UTC by Dirk Mueller
Modified: 2006-02-16 00:57 UTC (History)
10 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dirk Mueller 2006-02-16 00:27:32 UTC
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 &#8216;void QHash<Key>::findNode(const Key&) [with Key = khtml::Font::ScalKey]&#8217;:
font-testcase.cpp:29:   instantiated from here
font-testcase.cpp:6: error: no matching function for call to &#8216;qHash(const khtml::Font::ScalKey&)&#8217;
font-testcase.cpp:1: note: candidates are: int qHash(char)
font-testcase.cpp:2: note:                 int qHash(int)
Comment 1 Andrew Pinski 2006-02-16 00:33:11 UTC
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 ***
Comment 2 Dirk Mueller 2006-02-16 00:45:04 UTC
how do you explain that the testcase compiles just fine if you remove the namespace?

Comment 3 Andrew Pinski 2006-02-16 00:49:17 UTC
(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.
Comment 4 Andrew Pinski 2006-02-16 00:57:20 UTC
Please read the Defect report which takes about this case:
http://www.open-std.org/jtc1/sc22/wg21/prot/14882fdis/cwg_defects.html#197