bad_variant_access.pass.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. // XFAIL: dylib-has-no-bad_variant_access
  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(int, char**) {
  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. return 0;
  31. }