[Bug c++/51577] New: dependent name lookup finds operator in global namespace

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Dec 16 12:13:00 GMT 2011


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

             Bug #: 51577
           Summary: dependent name lookup finds operator in global
                    namespace
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: redi@gcc.gnu.org


template<typename T, typename U>
bool test( T v1, U v2 )
{
    // g(v1, v2);  // fails
    v1 == v2;
}

namespace A {
    struct X { };
}

namespace B {
    struct Y { };
}

void g(A::X, B::Y) { }

bool operator==(A::X, B::Y) { return true; }


int main()
{
  test( A::X(), B::Y() );
}

This should be rejected, but lookup using associated namespaces finds
operator== in the global namespace.  It should only look in namespace A.

If the call uses the function g() instead of an operator, name lookup fails as
expected.  If namespace A and the operator== are in an enclosing namespace it
also fails, the bug only seems to happen when operator== is in the global
namespace.



More information about the Gcc-bugs mailing list