bad_variant_access.pass.cpp 981 B

12345678910111213141516171819202122232425262728293031323334353637
  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. /*
  13. class bad_variant_access : public exception {
  14. public:
  15. bad_variant_access() noexcept;
  16. virtual const char* what() const noexcept;
  17. };
  18. */
  19. #include <cassert>
  20. #include <exception>
  21. #include <type_traits>
  22. #include <variant>
  23. int main() {
  24. static_assert(std::is_base_of<std::exception, std::bad_variant_access>::value,
  25. "");
  26. static_assert(noexcept(std::bad_variant_access{}), "must be noexcept");
  27. static_assert(noexcept(std::bad_variant_access{}.what()), "must be noexcept");
  28. std::bad_variant_access ex;
  29. assert(ex.what());
  30. }