c_implicit_ctor.cpp 946 B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright (c) 2018 Andrey Semashev
  2. //
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. // The test verifies that atomic<T> has an implicit conversion constructor from T.
  7. // This can only be tested in C++17 because it has mandated copy elision. Previous C++ versions
  8. // also require atomic<> to have a copy or move constructor, which it does not.
  9. #if __cplusplus >= 201703L
  10. #include <boost/atomic.hpp>
  11. #include <boost/static_assert.hpp>
  12. #include <boost/config.hpp>
  13. #include <type_traits>
  14. int main(int, char *[])
  15. {
  16. static_assert(std::is_convertible< int, boost::atomic< int > >::value, "boost::atomic<T> does not have an implicit constructor from T");
  17. boost::atomic< short > a = 10;
  18. (void)a;
  19. return 0;
  20. }
  21. #else // __cplusplus >= 201703L
  22. int main(int, char *[])
  23. {
  24. return 0;
  25. }
  26. #endif // __cplusplus >= 201703L