91 lines · plain
1.. title:: clang-tidy - modernize-use-noexcept2 3modernize-use-noexcept4======================5 6This check replaces deprecated dynamic exception specifications with7the appropriate noexcept specification (introduced in C++11). By8default this check will replace ``throw()`` with ``noexcept``,9and ``throw(<exception>[,...])`` or ``throw(...)`` with10``noexcept(false)``.11 12Example13-------14 15.. code-block:: c++16 17 void foo() throw();18 void bar() throw(int) {}19 20transforms to:21 22.. code-block:: c++23 24 void foo() noexcept;25 void bar() noexcept(false) {}26 27Options28-------29 30.. option:: ReplacementString31 32 Users can use :option:`ReplacementString` to specify a macro to use33 instead of ``noexcept``. This is useful when maintaining source code34 that uses custom exception specification marking other than35 ``noexcept``. Fix-it hints will only be generated for non-throwing36 specifications.37 38Example39^^^^^^^40 41.. code-block:: c++42 43 void bar() throw(int);44 void foo() throw();45 46transforms to:47 48.. code-block:: c++49 50 void bar() throw(int); // No fix-it generated.51 void foo() NOEXCEPT;52 53if the :option:`ReplacementString` option is set to `NOEXCEPT`.54 55.. option:: UseNoexceptFalse56 57Enabled by default, disabling will generate fix-it hints that remove58throwing dynamic exception specs, e.g., ``throw(<something>)``,59completely without providing a replacement text, except for60destructors and delete operators that are ``noexcept(true)`` by61default.62 63Example64^^^^^^^65 66.. code-block:: c++67 68 void foo() throw(int) {}69 70 struct bar {71 void foobar() throw(int);72 void operator delete(void *ptr) throw(int);73 void operator delete[](void *ptr) throw(int);74 ~bar() throw(int);75 }76 77transforms to:78 79.. code-block:: c++80 81 void foo() {}82 83 struct bar {84 void foobar();85 void operator delete(void *ptr) noexcept(false);86 void operator delete[](void *ptr) noexcept(false);87 ~bar() noexcept(false);88 }89 90if the :option:`UseNoexceptFalse` option is set to `false`.91