Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

15
  • 67
    Additional information: And you can test whether or not your expectations have been met: static_assert(std::is_nothrow_move_constructible<MyType>::value, "MyType should be noexcept MoveConstructible"); Commented Sep 6, 2013 at 15:17
  • 1
    So all functions invoked by the implicit special member functions must be declared noexcept for the implicit special member functions to be noexcept. Means you have to be diligent enough to mark all relevant functions noexcept, means there is a lot room for human error, right? Commented Nov 3, 2015 at 13:29
  • 2
    @mucaho: Well, if all your members themselves only use implicitly defined special members, then this isn't all that complex. The simple rule is the rule of single responsibility, and by default the only human error you should watch out for is defining special member functions explicitly. That only leaves special-purpose classes (such as unique_ptr) that you need to vet. Commented Nov 4, 2015 at 0:11
  • 15
    What about explicitly declared special member function with default? Such as void T(T &&) = default. Am I correct to assume that it behaves exactly the same if this move constructor is implicitly declared if not prevented by other conditions, such as a user-defined copy constructor? Commented Dec 14, 2016 at 16:28
  • 6
    @YanZhou Yes, explicitly defaulted Special member functions also follow those rules unless explicitly overridden for constexpr and noexcept. Your example has a spurious void though, so it is a compile-error. Commented Aug 14, 2018 at 16:56