dtor_pass.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. // Copyright (C) 2011 Vicente J. Botet Escriba
  10. //
  11. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  12. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  13. // <boost/thread/future.hpp>
  14. // class promise<R>
  15. // ~promise();
  16. #define BOOST_THREAD_VERSION 3
  17. #include <boost/thread/future.hpp>
  18. #include <boost/detail/lightweight_test.hpp>
  19. int main()
  20. {
  21. {
  22. typedef int T;
  23. boost::future<T> f;
  24. {
  25. boost::promise<T> p;
  26. f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
  27. p.set_value(3);
  28. }
  29. BOOST_TEST(f.get() == 3);
  30. }
  31. {
  32. typedef int T;
  33. boost::future<T> f;
  34. {
  35. boost::promise<T> p;
  36. f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
  37. }
  38. try
  39. {
  40. //T i =
  41. (void)f.get();
  42. BOOST_TEST(false);
  43. }
  44. catch (const boost::future_error& e)
  45. {
  46. BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::broken_promise));
  47. }
  48. }
  49. {
  50. typedef int& T;
  51. int i = 4;
  52. boost::future<T> f;
  53. {
  54. boost::promise<T> p;
  55. f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
  56. p.set_value(i);
  57. }
  58. BOOST_TEST(&f.get() == &i);
  59. }
  60. {
  61. typedef int& T;
  62. boost::future<T> f;
  63. {
  64. boost::promise<T> p;
  65. f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
  66. }
  67. try
  68. {
  69. //T i =
  70. (void)f.get();
  71. BOOST_TEST(false);
  72. }
  73. catch (const boost::future_error& e)
  74. {
  75. BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::broken_promise));
  76. }
  77. }
  78. {
  79. typedef void T;
  80. boost::future<T> f;
  81. {
  82. boost::promise<T> p;
  83. f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
  84. p.set_value();
  85. }
  86. f.get();
  87. BOOST_TEST(true);
  88. }
  89. {
  90. typedef void T;
  91. boost::future<T> f;
  92. {
  93. boost::promise<T> p;
  94. f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
  95. }
  96. try
  97. {
  98. f.get();
  99. BOOST_TEST(false);
  100. }
  101. catch (const boost::future_error& e)
  102. {
  103. BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::broken_promise));
  104. }
  105. }
  106. return boost::report_errors();
  107. }