Does it make sense to declare a remote function as noexcept?

Consider these two possible definitions for a class:

Figure A:

struct A { A() = delete; }; 

Exhibit A ':

 struct A { A() noexcept = delete; } 

Does it make sense to declare a remote function as noexcept ?

+7
c ++ noexcept deleted-functions
source share
1 answer

(This was originally posted as a comment, but it is recommended to post as an answer.)

Simply no. A function that is deleted cannot be called (or, in the case of the constructor used to initialize the object), not to mention an exception.

Edit:

hvd mentioned in the comments below that noexcept(f()) does not call f() . If the constructor of class A is delete d, then noexcept(A()) will not be able to compile, regardless of whether the constructor is noexcept . This is (essentially) a consequence of the requirement that noexcept(expression) be given the correct expression - and the expression A() for class A requires a valid constructor.

Revolver_Ocelot also correctly indicates that it is impossible to overload noexcept (i.e. it is impossible to have two functions with the same signature, except that one is noexcept and the other is not). Thus, in the definition of class A both A() = delete and A() noexcept = delete have the same effect, i.e. Class A has no constructor with no arguments.

+7
source share

All Articles