Debian Codegraph @

clang-tools-extra/docs/clang-tidy/checks/modernize/use-noexcept.rst

raw
1 .. title:: clang-tidy - modernize-use-noexcept
2
3 modernize-use-noexcept
4 ======================
5
6 This check replaces deprecated dynamic exception specifications with
7 the appropriate noexcept specification (introduced in C++11). By
8 default this check will replace ``throw()`` with ``noexcept``,
9 and ``throw(<exception>[,...])`` or ``throw(...)`` with
10 ``noexcept(false)``.
11
12 Example
13 -------
14
15 .. code-block:: c++
16
17 void foo() throw();
18 void bar() throw(int) {}
19
20 transforms to:
21
22 .. code-block:: c++
23
24 void foo() noexcept;
25 void bar() noexcept(false) {}
26
27 Options
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
38 Example
39 ^^^^^^^
40
41 .. code-block:: c++
42
43 void bar() throw(int);
44 void foo() throw();
45
46 transforms to:
47
48 .. code-block:: c++
49
50 void bar() throw(int); // No fix-it generated.
51 void foo() NOEXCEPT;
52
53 if the :option:`ReplacementString` option is set to `NOEXCEPT`.
54
55 .. option:: UseNoexceptFalse
56
57 Enabled by default, disabling will generate fix-it hints that remove
58 throwing dynamic exception specs, e.g., ``throw(<something>)``,
59 completely without providing a replacement text, except for
60 destructors and delete operators that are ``noexcept(true)`` by
61 default.
62
63 Example
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
77 transforms 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
90 if the :option:`UseNoexceptFalse` option is set to `false`.