Git's source code contains a peculiarly named global variable `false_but_the_compiler_does_not_know_it_`, always initialized to 0 but never declared `const` and defined in a separate translation unit. This prevents Clang's `-Wunreachable-code` warning from firing on code that is only unreachable in certain build configurations (e.g., when `NO_SYMLINK_HEAD` is defined and `create_ref_symlink` becomes a constant `-1`). The `NOT_CONSTANT` macro wraps expressions with this variable via logical OR, making the compiler unable to prove the condition is always false at compile time. Alternative approaches like `#ifdef` guards, `#pragma` suppression, `volatile`, or a stub function are discussed and compared. The post also explores whether link-time optimization (LTO) eliminates the dead branch — it does, giving Git both warning suppression during normal builds and dead-code elimination with LTO enabled.
Table of contents
Where Git Uses This TrickWhy Git Added This MacroCould This Be Done Differently?Does the Linker Remove This Branch?17.3K Impressions2 Comments