no_rvalue_to_nonconst_visitation.cpp 840 B

1234567891011121314151617181920212223242526272829303132
  1. // Copyright (c) 2017-2019 Antony Polukhin
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See
  4. // accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #include "boost/config.hpp"
  7. #include "boost/variant.hpp"
  8. struct foo {};
  9. struct some_user_provided_visitor_for_lvalues: boost::static_visitor<void> {
  10. void operator()(foo& ) const {}
  11. void operator()(int ) const {}
  12. };
  13. int main() {
  14. boost::apply_visitor(
  15. some_user_provided_visitor_for_lvalues(),
  16. boost::variant<int, foo>(foo())
  17. );
  18. #ifdef __GNUC__
  19. # if __GNUC__ < 5 && __GNUC_MINOR__ < 8
  20. # error This test does not pass on GCC < 4.8 because of the incomplete C++11 support
  21. # endif
  22. #endif
  23. #ifdef BOOST_MSVC
  24. # error Temporaries/rvalues could bind to non-const lvalues on MSVC compilers
  25. #endif
  26. }