summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/other/ptrmem1.C
blob: fa9115e506c1e8fbad42edff8afab7e5027c8677 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// { dg-do run }

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

// PR 4379. We created pointers to member references and pointers to
// member fields when we shouldn't have.

int gs;
int gm;

struct D {
  D () :m (gm) {}
  
  int &m;
  static int &s;
  
  int Foo ();
};

int &D::s = gs;

template<class T> int f1(T x)
{
  return x != &gm;
}
template<class T> int f2(T x) 
{
  return x != &gs;
}

int D::Foo ()
{
  int r;
  
  if (f1( &(D::m)))
    return 3;
  
  if (f2( &D::s))
    return 1;
  if (f2( &(D::s)))
    return 2;
  return 0;
}

int Foo ()
{
  if (f2( &D::s))
    return 4;
  if (f2( &(D::s)))
    return 5;
  return 0;
}

int main ()
{
  D d;
  int r = d.Foo ();
  if (r)
    return r;
  r = Foo ();
  if (r)
    return r;
  return 0;
  
}