The following program should compile (and does on recently EDG-base compilers),
because the operator== is build when the template is parsed (it is
non-dependent). However, GCC looks up the == operator at instantiation time and
finds the second, incorrect definition of operator==. This is similar to Bug
2922, but deals with operators instead of normal function names, which GCC
handles (very) differently internally.

template<class T> struct wrap {};

template<typename T> bool& operator==(wrap<T>, wrap<T>);

template<typename T>
void g(T, wrap<wrap<int> > x)
{
  bool& b = x == x;
}

template<typename T> int& operator==(wrap<wrap<T> >, wrap<wrap<T> >);

void h()
{
  wrap<wrap<int> > x;
  g(17, x);
}

-- 
           Summary: Two-stage name lookup fails for operations
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: doug dot gregor at gmail dot com
                CC: gcc-bugs at gcc dot gnu dot org


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

Reply via email to