valueless_by_exception.pass.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // UNSUPPORTED: c++98, c++03, c++11, c++14
  10. // <variant>
  11. // template <class ...Types> class variant;
  12. // constexpr bool valueless_by_exception() const noexcept;
  13. #include <cassert>
  14. #include <string>
  15. #include <type_traits>
  16. #include <variant>
  17. #include "archetypes.h"
  18. #include "test_macros.h"
  19. #include "variant_test_helpers.h"
  20. int main(int, char**) {
  21. {
  22. using V = std::variant<int, long>;
  23. constexpr V v;
  24. static_assert(!v.valueless_by_exception(), "");
  25. }
  26. {
  27. using V = std::variant<int, long>;
  28. V v;
  29. assert(!v.valueless_by_exception());
  30. }
  31. {
  32. using V = std::variant<int, long, std::string>;
  33. const V v("abc");
  34. assert(!v.valueless_by_exception());
  35. }
  36. #ifndef TEST_HAS_NO_EXCEPTIONS
  37. {
  38. using V = std::variant<int, MakeEmptyT>;
  39. V v;
  40. assert(!v.valueless_by_exception());
  41. makeEmpty(v);
  42. assert(v.valueless_by_exception());
  43. }
  44. #endif
  45. return 0;
  46. }