1.. title:: clang-tidy - readability-avoid-return-with-void-value
2
3readability-avoid-return-with-void-value
4========================================
5
6Finds return statements with ``void`` values used within functions with
7``void`` result types.
8
9A function with a ``void`` return type is intended to perform a task without
10producing a return value. Return statements with expressions could lead
11to confusion and may miscommunicate the function's intended behavior.
12
13Example:
14
15.. code-block::
16
17   void g();
18   void f() {
19       // ...
20       return g();
21   }
22
23In a long function body, the ``return`` statement suggests that the function
24returns a value. However, ``return g();`` is a combination of two statements
25that should be written as
26
27.. code-block::
28
29   g();
30   return;
31
32to make clear that ``g()`` is called and immediately afterwards the function
33returns (nothing).
34
35In C, the same issue is detected by the compiler if the ``-Wpedantic`` mode
36is enabled.
37
38Options
39-------
40
41.. option::  IgnoreMacros
42
43  The value `false` specifies that return statements expanded
44  from macros are not checked. The default value is `true`.
45
46.. option::  StrictMode
47
48  The value `false` specifies that a direct return statement shall
49  be excluded from the analysis if it is the only statement not
50  contained in a block, like ``if (cond) return g();``. The default
51  value is `true`.
52