2

Does it makes sense to specify noexcept on, for example. a deleted move assignment operator? For example:

struct A
{
    A& operator=( A&& ) noexcept = delete;
};

What would change if I do not specify it, and I just write:

struct A
{
    A& operator=( A&& ) = delete;
};
nyarlathotep108
  • 5,275
  • 2
  • 26
  • 64
  • A comment not on _"makes sense"_, but on the possible effects of it (which is not covered in the linked answer): the [`noexcept` operator](https://en.cppreference.com/w/cpp/language/noexcept) will evaluate `noexcept(A::operator=)` to `true` or `false` depending on if `A::operator=` is specified as `noexcept` or not, respectively, regardless of whether `A::operator=` is deleted or not. – dfrib Jan 15 '19 at 16:30
  • Are you sure that `A::operator=` would be available to it even if deleted? It sounds weird... – nyarlathotep108 Jan 15 '19 at 16:40
  • 1
    The `noexcept` operator is a compile time check that does not evaluate its expression, so yes, it may be invoked even on a deleted operator. _However_, I just noticed that from C++17 an onwards, the behavior of the `noexcept` operator has changed to _"The result is `true` if the set of potential exceptions of the expression is empty, and false otherwise."_, meaning that `noexcept(A::operator=)`, for C++17, will return `true` even if `A::operator=` is not marker with `noexcept`, as a deleted operator cannot potentially throw any exceptions. Pre-C++17, this would return `false`. – dfrib Jan 15 '19 at 17:11

0 Answers0