http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56943



             Bug #: 56943

           Summary: Incorrect two-phase name lookup for operators

    Classification: Unclassified

           Product: gcc

           Version: 4.9.0

            Status: UNCONFIRMED

          Severity: normal

          Priority: P3

         Component: c++

        AssignedTo: unassig...@gcc.gnu.org

        ReportedBy: zeratul...@hotmail.com





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.

Reply via email to