dtor_noexcept.pass.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // UNSUPPORTED: c++98, c++03
  9. // <string>
  10. // ~basic_string() // implied noexcept;
  11. #include <string>
  12. #include <cassert>
  13. #include "test_macros.h"
  14. #include "test_allocator.h"
  15. template <class T>
  16. struct throwing_alloc
  17. {
  18. typedef T value_type;
  19. throwing_alloc(const throwing_alloc&);
  20. T *allocate(size_t);
  21. ~throwing_alloc() noexcept(false);
  22. };
  23. // Test that it's possible to take the address of basic_string's destructors
  24. // by creating globals which will register their destructors with cxa_atexit.
  25. std::string s;
  26. std::wstring ws;
  27. int main(int, char**)
  28. {
  29. {
  30. typedef std::string C;
  31. static_assert(std::is_nothrow_destructible<C>::value, "");
  32. }
  33. {
  34. typedef std::basic_string<char, std::char_traits<char>, test_allocator<char>> C;
  35. static_assert(std::is_nothrow_destructible<C>::value, "");
  36. }
  37. #if defined(_LIBCPP_VERSION)
  38. {
  39. typedef std::basic_string<char, std::char_traits<char>, throwing_alloc<char>> C;
  40. static_assert(!std::is_nothrow_destructible<C>::value, "");
  41. }
  42. #endif // _LIBCPP_VERSION
  43. return 0;
  44. }