xref: /llvm-project/clang-tools-extra/docs/clang-tidy/checks/modernize/use-noexcept.rst (revision 6e566bc5523f743bc34a7e26f050f1f2b4d699a8)
1.. title:: clang-tidy - modernize-use-noexcept
2
3modernize-use-noexcept
4======================
5
6This check replaces deprecated dynamic exception specifications with
7the appropriate noexcept specification (introduced in C++11). By
8default this check will replace ``throw()`` with ``noexcept``,
9and ``throw(<exception>[,...])`` or ``throw(...)`` with
10``noexcept(false)``.
11
12Example
13-------
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
27Options
28-------
29
30.. option:: ReplacementString
31
32  Users can use :option:`ReplacementString` to specify a macro to use
33  instead of ``noexcept``. This is useful when maintaining source code
34  that uses custom exception specification marking other than
35  ``noexcept``. Fix-it hints will only be generated for non-throwing
36  specifications.
37
38Example
39^^^^^^^
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:: UseNoexceptFalse
56
57Enabled by default, disabling will generate fix-it hints that remove
58throwing dynamic exception specs, e.g., ``throw(<something>)``,
59completely without providing a replacement text, except for
60destructors and delete operators that are ``noexcept(true)`` by
61default.
62
63Example
64^^^^^^^
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