libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

dtor_noexcept.pass.cpp (1418B)


      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 
     10 // UNSUPPORTED: c++98, c++03
     11 
     12 // <string>
     13 
     14 // ~basic_string() // implied noexcept;
     15 
     16 #include <string>
     17 #include <cassert>
     18 
     19 #include "test_macros.h"
     20 #include "test_allocator.h"
     21 
     22 template <class T>
     23 struct throwing_alloc
     24 {
     25     typedef T value_type;
     26     throwing_alloc(const throwing_alloc&);
     27     T *allocate(size_t);
     28     ~throwing_alloc() noexcept(false);
     29 };
     30 
     31 // Test that it's possible to take the address of basic_string's destructors
     32 // by creating globals which will register their destructors with cxa_atexit.
     33 std::string s;
     34 std::wstring ws;
     35 
     36 int main()
     37 {
     38     {
     39         typedef std::string C;
     40         static_assert(std::is_nothrow_destructible<C>::value, "");
     41     }
     42     {
     43         typedef std::basic_string<char, std::char_traits<char>, test_allocator<char>> C;
     44         static_assert(std::is_nothrow_destructible<C>::value, "");
     45     }
     46 #if defined(_LIBCPP_VERSION)
     47     {
     48         typedef std::basic_string<char, std::char_traits<char>, throwing_alloc<char>> C;
     49         static_assert(!std::is_nothrow_destructible<C>::value, "");
     50     }
     51 #endif // _LIBCPP_VERSION
     52 }