valueless_by_exception.pass.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // The LLVM Compiler Infrastructure
  5. //
  6. // This file is dual licensed under the MIT and the University of Illinois Open
  7. // Source Licenses. See LICENSE.TXT for details.
  8. //
  9. //===----------------------------------------------------------------------===//
  10. // UNSUPPORTED: c++98, c++03, c++11, c++14
  11. // <variant>
  12. // template <class ...Types> class variant;
  13. // constexpr bool valueless_by_exception() const noexcept;
  14. #include <cassert>
  15. #include <string>
  16. #include <type_traits>
  17. #include <variant>
  18. #include "archetypes.hpp"
  19. #include "test_macros.h"
  20. #include "variant_test_helpers.hpp"
  21. int main() {
  22. {
  23. using V = std::variant<int, ConstexprTestTypes::NoCtors>;
  24. constexpr V v;
  25. static_assert(!v.valueless_by_exception(), "");
  26. }
  27. {
  28. using V = std::variant<int, long, std::string>;
  29. const V v("abc");
  30. assert(!v.valueless_by_exception());
  31. }
  32. #ifndef TEST_HAS_NO_EXCEPTIONS
  33. {
  34. using V = std::variant<int, MakeEmptyT>;
  35. V v;
  36. assert(!v.valueless_by_exception());
  37. makeEmpty(v);
  38. assert(v.valueless_by_exception());
  39. }
  40. #endif
  41. }