This is not a good idea, no. The reason is that the standard knows that sometimes it is impossible to ensure the correctness of throw() , for which throw() was first introduced. In particular, in the case of patterns where an exception may or may not be selected depending on the instance, it is not possible to verify the correctness without creating a pattern. Therefore, the standard does not require compilers to enforce an exception specifier; in fact, it prohibits the implementation from rejecting the expression “simply because, when executed, it throws or can throw an exception that the containing function does not allow” (15.4 / 11).
If throw() has no effect other than documentation, it should be commented out; thus, at least, this does not constitute a danger to mislead the human observer.
The case with noexcept completely different. noexcept occurs for another reason; that performance. If you can guarantee that the compiler does not throw any exceptions, the compiler allows itself to perform some optimizations. But you will have to do the checks yourself. So, if swap() really doesn't throw out (and it shouldn't be that its raison d'être), then specifying noexcept is a good idea.
wilhelmtell
source share