33 lines · plain
1.. title:: clang-tidy - readability-avoid-unconditional-preprocessor-if2 3readability-avoid-unconditional-preprocessor-if4===============================================5 6Finds code blocks that are constantly enabled or disabled in preprocessor7directives by analyzing ``#if`` conditions, such as ``#if 0`` and ``#if 1``,8etc.9 10.. code-block:: c++11 12 #if 013 // some disabled code14 #endif15 16 #if 117 // some enabled code that can be disabled manually18 #endif19 20Unconditional preprocessor directives, such as ``#if 0`` for disabled code21and ``#if 1`` for enabled code, can lead to dead code and always enabled code,22respectively. Dead code can make understanding the codebase more difficult,23hinder readability, and may be a sign of unfinished functionality or abandoned24features. This can cause maintenance issues, confusion for future developers,25and potential compilation problems.26 27As a solution for both cases, consider using preprocessor macros or defines,28like ``#ifdef DEBUGGING_ENABLED``, to control code enabling or disabling.29This approach provides better coordination and flexibility when working with30different parts of the codebase. Alternatively, you can comment out the entire31code using ``/* */`` block comments and add a hint, such as ``@todo``,32to indicate future actions.33