optional_test_fail_explicit_convert_in_value_or.cpp 594 B

1234567891011121314151617181920212223242526272829303132
  1. // Copyright (C) 2014, Andrzej Krzemienski.
  2. //
  3. // Use, modification, and distribution is subject to the Boost Software
  4. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/lib/optional for documentation.
  8. //
  9. // You are welcome to contact the author at:
  10. // akrzemi1@gmail.com
  11. //
  12. #include "boost/optional.hpp"
  13. //
  14. // THIS TEST SHOULD FAIL TO COMPILE
  15. //
  16. struct U
  17. {};
  18. struct T
  19. {
  20. explicit T(U const&) {}
  21. };
  22. void test_implicit_conversion_to_bool()
  23. {
  24. boost::optional<T> opt;
  25. opt.value_or(U());
  26. }