default_noexcept.pass.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // <string>
  10. // basic_string()
  11. // noexcept(is_nothrow_default_constructible<allocator_type>::value);
  12. // This tests a conforming extension
  13. #include <string>
  14. #include <cassert>
  15. #include "test_macros.h"
  16. #include "test_allocator.h"
  17. template <class T>
  18. struct some_alloc
  19. {
  20. typedef T value_type;
  21. some_alloc(const some_alloc&);
  22. };
  23. int main()
  24. {
  25. #if __has_feature(cxx_noexcept)
  26. {
  27. typedef std::string C;
  28. static_assert(std::is_nothrow_default_constructible<C>::value, "");
  29. }
  30. {
  31. typedef std::basic_string<char, std::char_traits<char>, test_allocator<char>> C;
  32. static_assert(std::is_nothrow_default_constructible<C>::value, "");
  33. }
  34. {
  35. typedef std::basic_string<char, std::char_traits<char>, some_alloc<char>> C;
  36. // See N4258 - basic_string<char, traits, Allocator>::basic_string() noexcept;
  37. #if TEST_STD_VER <= 14
  38. static_assert(!std::is_nothrow_default_constructible<C>::value, "");
  39. #else
  40. static_assert( std::is_nothrow_default_constructible<C>::value, "");
  41. #endif
  42. }
  43. #endif
  44. }