| 1 |
.. title:: clang-tidy - readability-avoid-nested-conditional-operator |
| 2 |
|
| 3 |
readability-avoid-nested-conditional-operator |
| 4 |
============================================= |
| 5 |
|
| 6 |
Identifies instances of nested conditional operators in the code. |
| 7 |
|
| 8 |
Nested conditional operators, also known as ternary operators, can contribute |
| 9 |
to reduced code readability and comprehension. So they should be split as |
| 10 |
several statements and stored the intermediate results in temporary variable. |
| 11 |
|
| 12 |
Examples: |
| 13 |
|
| 14 |
.. code-block:: c++ |
| 15 |
|
| 16 |
int NestInConditional = (condition1 ? true1 : false1) ? true2 : false2; |
| 17 |
int NestInTrue = condition1 ? (condition2 ? true1 : false1) : false2; |
| 18 |
int NestInFalse = condition1 ? true1 : condition2 ? true2 : false1; |
| 19 |
|
| 20 |
This check implements part of `AUTOSAR C++14 Rule A5-16-1 |
| 21 |
<https://www.autosar.org/fileadmin/standards/R22-11/AP/AUTOSAR_RS_CPP14Guidelines.pdf>`_. |