view gcc/testsuite/g++.dg/template/const1.C @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 04ced10e8804
children
line wrap: on
line source

// 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;
}