summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/other/ptrmem2.C
blob: d267df15be163dbdbef634c5e6600dc6e838847b (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
// { dg-do compile }

// Copyright (C) 2001, 2002 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.

struct D {
  
  int &m;       // { dg-error "invalid use of non-static data member" "" }
  static int &s;
  
  int Foo ();
};

template<class T> int f1(T x);
template<class T> int f2(T x);

int D::Foo ()
{
  f1( &D::m);   // { dg-error "cannot create pointer to ref" "" }
  f1( &(D::m));	// ok
  f2( &D::s);   // ok
  f2( &(D::s)); // ok
  return 0;
}

int Foo ()
{
  f1( &D::m);    // { dg-error "cannot create pointer to ref" "" }
  f1( &(D::m));  // { dg-error "from this location" "" }
  f2( &D::s);    // ok
  f2( &(D::s));  // ok
  return 0;
}