Git fork

refs: forbid clang to complain about unreachable code

When `NO_SYMLINK_HEAD` is defined, `create_ref_symlink()` is hard-coded
as `(-1)`, and as a consequence the condition `!create_ref_symlink()`
always evaluates to false, rendering any code guarded by that condition
unreachable.

Therefore, clang is _technically_ correct when it complains about
unreachable code. It does completely miss the fact that this is okay
because on _other_ platforms, where `NO_SYMLINK_HEAD` is not defined,
the code isn't unreachable at all.

Let's use the same trick as in 82e79c63642c (git-compat-util: add
NOT_CONSTANT macro and use it in atfork_prepare(), 2025-03-17) to
appease clang while at the same time keeping the `-Wunreachable` flag
to potentially find _actually_ unreachable code.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Johannes Schindelin and committed by
Junio C Hamano
38609851 c44beea4

+7 -1
+7 -1
refs/files-backend.c
··· 3186 3186 * next update. If not, we try and create a regular symref. 3187 3187 */ 3188 3188 if (update->new_target && refs->prefer_symlink_refs) 3189 - if (!create_ref_symlink(lock, update->new_target)) 3189 + /* 3190 + * By using the `NOT_CONSTANT()` trick, we can avoid 3191 + * errors by `clang`'s `-Wunreachable` logic that would 3192 + * report that the `continue` statement is not reachable 3193 + * when `NO_SYMLINK_HEAD` is `#define`d. 3194 + */ 3195 + if (NOT_CONSTANT(!create_ref_symlink(lock, update->new_target))) 3190 3196 continue; 3191 3197 3192 3198 if (update->flags & REF_NEEDS_COMMIT) {