c++c++11stdnoexcept

Why is the clear() function noexcept while the destructor not?


I noticed that, in the allocator-aware containers interface, the standard requires that the clear() member function be noexcept while the destructor not. Furthermore, it appears a discrepancy in the case of some node-based containers, such as std::forward_list and std::set, since the clear() member function performs the same operation as the destructor.

Is there any reason for this difference?


Solution

  • Destructors are implicitly noexcept unless any of the member variable destructors or base class destructors have been marked with noexcept(false) or the destructor itself is explicitly marked with noexcept(false).