summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/template/friend10.C
blob: cab5e346f0bf397454d09926fbcc68689f0d4a65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// { dg-do run }

// Copyright (C) 2002 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 24 Dec 2002 <nathan@codesourcery.com>

// PR 5116. template instantiation can add a friend into a namespace,
// and thus change overload resolution.

#include <iostream>

static int right;
static int wrong;

struct Buggy {};

template <typename T>struct Handle
{
  Handle(T* p) {}
  
  operator bool() const { wrong++; return true; }
  
  friend std::ostream& operator<<(std::ostream& ostr, const Handle& r)
  {
    right++;
    
    return ostr << "in operator<<(ostream&, const Handle&)";
  }
};

typedef Handle<Buggy>     Buggy_h;

bool cmp (const Buggy_h& b1, const Buggy_h& b2)
{
  std::cout << b1 << " " << b2 << std::endl;
  return false;
}

int main()
{
  Buggy o;
  
  cmp (&o, &o);

  return !(right == 2 && !wrong);
}