nullptr_t_assign.pass.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // <functional>
  10. // class function<R(ArgTypes...)>
  11. // function& operator=(nullptr_t);
  12. #include <functional>
  13. #include <cassert>
  14. #include "count_new.hpp"
  15. class A
  16. {
  17. int data_[10];
  18. public:
  19. static int count;
  20. A()
  21. {
  22. ++count;
  23. for (int i = 0; i < 10; ++i)
  24. data_[i] = i;
  25. }
  26. A(const A&) {++count;}
  27. ~A() {--count;}
  28. int operator()(int i) const
  29. {
  30. for (int j = 0; j < 10; ++j)
  31. i += data_[j];
  32. return i;
  33. }
  34. };
  35. int A::count = 0;
  36. int g(int) {return 0;}
  37. int main()
  38. {
  39. assert(globalMemCounter.checkOutstandingNewEq(0));
  40. {
  41. std::function<int(int)> f = A();
  42. assert(A::count == 1);
  43. assert(globalMemCounter.checkOutstandingNewEq(1));
  44. assert(f.target<A>());
  45. f = nullptr;
  46. assert(A::count == 0);
  47. assert(globalMemCounter.checkOutstandingNewEq(0));
  48. assert(f.target<A>() == 0);
  49. }
  50. {
  51. std::function<int(int)> f = g;
  52. assert(globalMemCounter.checkOutstandingNewEq(0));
  53. assert(f.target<int(*)(int)>());
  54. assert(f.target<A>() == 0);
  55. f = nullptr;
  56. assert(globalMemCounter.checkOutstandingNewEq(0));
  57. assert(f.target<int(*)(int)>() == 0);
  58. }
  59. }