The following code does not compile because class TestBad has both template in
template argument T2 and friend operators.

template <class T>
class Temp {};

template <class T1, template <class> class T2>
class TestBad
{
public:
  template <class OtherT1, template <class> class OtherT2>
  friend bool operator == (const TestBad<OtherT1, OtherT2>& a, const
TestBad<OtherT1, OtherT2>& b);
  template <class OtherT1, template <class> class OtherT2>
  friend bool operator != (const TestBad<OtherT1, OtherT2>& a, const
TestBad<OtherT1, OtherT2>& b);

private:
  T2<T1> vector;
};

template <class OtherT1, template <class> class OtherT2>
bool operator == (const TestBad<OtherT1, OtherT2>& a, const TestBad<OtherT1,
OtherT2>& b)
{
  (void)a;
  (void)b;
  return true;
}

template <class OtherT1, template <class> class OtherT2>
bool operator != (const TestBad<OtherT1, OtherT2>& a, const TestBad<OtherT1,
OtherT2>& b)
{
  (void)a;
  (void)b;
  return false;
}

int main(int argc, char* argv[])
{
  bool result;
  TestBad<int, Temp> a;
  TestBad<int, Temp> b;

  result = (a == b);

  (void)a;
  (void)b;
  (void)result;
  (void)argc;
  (void)argv;
  return 0;
}

I've tried with gcc 3.4.4 in Mingw32 and it shows me the following error
message:

test.cpp: In function `int main(int, char**)':
test.cpp:43: error: ambiguous overload for 'operator==' i
n 'a == b'
test.cpp:23: note: candidates are: bool operator==(const
TestBad<OtherT1, OtherT2>&, const TestBad<OtherT1, OtherT2>&) [with OtherT1 =
in
t, OtherT2 = Temp]
test.cpp:13: note:                 bool operator==(const
TestBad<OtherT1, OtherT2>&, const TestBad<OtherT1, OtherT2>&) [with OtherT1 =
in
t, OtherT2 = Temp, T1 = int, T2 = Temp]

PS: With out template in template argument everything is fine!


-- 
           Summary: Friend operators for class with template in template
                    argument does not compile
           Product: gcc
           Version: 3.4.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: 4ekucT at tut dot by


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

Reply via email to