recursive_wrapper_move_test.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright (c) 2017
  2. // Mikhail Maximov
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #include "boost/config.hpp"
  8. #include "boost/core/lightweight_test.hpp"
  9. #ifdef __cpp_inheriting_constructors
  10. // Test is based on reported issue:
  11. // https://svn.boost.org/trac/boost/ticket/12680
  12. // GCC 6 crashed, trying to determine is boost::recursive_wrapper<Node>
  13. // is_noexcept_move_constructible
  14. #include <string>
  15. #include <iterator>
  16. #include <boost/variant.hpp>
  17. #include <boost/array.hpp>
  18. struct Leaf { };
  19. struct Node;
  20. typedef boost::variant<Leaf, boost::recursive_wrapper<Node>> TreeBase;
  21. struct Tree : TreeBase {
  22. using TreeBase::TreeBase;
  23. template <typename Iter>
  24. static Tree Create(Iter /*first*/, Iter /*last*/) { return Leaf{}; }
  25. };
  26. struct Node {
  27. Tree left, right;
  28. };
  29. // Test from https://svn.boost.org/trac/boost/ticket/7120
  30. template<class Node>
  31. struct node1_type;
  32. struct var_type;
  33. using var_base = boost::variant<int,
  34. boost::recursive_wrapper<node1_type<var_type>>
  35. >;
  36. template<class Node>
  37. struct node1_type {
  38. boost::array<Node, 1> children;
  39. };
  40. struct var_type : var_base {
  41. using var_base::var_base;
  42. };
  43. void run() {
  44. std::string input{"abracadabra"};
  45. const Tree root = Tree::Create(input.begin(), input.end());
  46. (void)root; // prevents unused variable warning
  47. var_type v1 = 1;
  48. (void)v1;
  49. }
  50. #else // #!ifdef __cpp_inheriting_constructors
  51. // if compiler does not support inheriting constructors - does nothing
  52. void run() {}
  53. #endif
  54. int main()
  55. {
  56. run();
  57. return boost::report_errors();
  58. }