summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/template/const1.C
blob: 629c4d4a916ea1016572fd4123a2f140d148954a (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
// PR c++/28385
// instantiating op() with void()() was making the compiler think that 'fcn'
// was const, so it could eliminate the call.

// { dg-do run }

extern "C" void abort (void);

int barcnt = 0;

class Foo {
  public:
    template<typename T>
    void operator()(const T& fcn) {
      fcn();
    }
};

void bar() {
  barcnt++;
}

int main() {
  Foo myFoo;
  myFoo(bar);
  myFoo(&bar);
  if (barcnt != 2)
    abort ();
  return 0;
}