Bug 56943 - Incorrect two-phase name lookup for operators
Summary: Incorrect two-phase name lookup for operators
Status: RESOLVED DUPLICATE of bug 51577
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-12 23:35 UTC by Nathan Ridge
Modified: 2013-04-13 00:44 UTC (History)
0 users

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 Nathan Ridge 2013-04-12 23:35:15 UTC
When the following code is run:


#include <iostream>

namespace N
{
    struct A
    {
        int operator+(const void*) 
        { 
            return 42; 
        }
    };
}

namespace M
{
    struct B
    {
    };
}


template <typename T, typename U>
int add(T t, U u)
{
    return t + u;
}

int operator+(N::A, M::B*) 
{ 
    return 5; 
}

int main(int argc, char** argv)
{
    N::A a;
    M::B b;
    std::cout << add(a, &b) << "\n";
}


the output is "5". I believe the correct output wouldbe "42", because when looking up operator+ in the expression "t + u", the operator+(N::A, M::B*) overload is found neither by unqualified lookup at the point of definition (since it is not declared yet at the point of definition), nor by argument-dependent lookup at the point of instantiation (since it is not in the namespace of either of its arguments).

Clang outputs "42" for this example, as expected.
Comment 1 Paolo Carlini 2013-04-13 00:33:04 UTC
Please double check this isn't a Dup of PR51577
Comment 2 Nathan Ridge 2013-04-13 00:44:58 UTC
(In reply to comment #1)
> Please double check this isn't a Dup of PR51577

Looks that way. Closing.

*** This bug has been marked as a duplicate of bug 51577 ***