view gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this8.C @ 158:494b0b89df80 default tip

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

// PR c++/56135
// { dg-do run { target c++11 } }

#include <functional>

struct test {
  template<typename T>
  std::function<void()> broken(int x) {
    return [=] { +x; print<T>(); }; // { dg-warning "implicit capture" "" { target c++2a } }
  }

  std::function<void()> works0() {
    return [=] { print<int>(); }; // { dg-warning "implicit capture" "" { target c++2a } }
  }

  template<typename T>
  std::function<void()> works1() {
    return [=] { print<int>(); }; // { dg-warning "implicit capture" "" { target c++2a } }
  }

  template<typename T>
  std::function<void()> works2() {
    return [=] { this->print<T>(); }; // { dg-warning "implicit capture" "" { target c++2a } }
  }

  template<typename T>
  void print() { if (this == 0) __builtin_abort (); }
};

int main(void) {
  test().broken<int>(1)();
  test().works0()();
  test().works1<int>()();
  test().works2<int>()();

  return 0;
}