Skip to content

Commit 75b23f9

Browse files
dschoGit for Windows Build Agent
authored andcommitted
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 82e79c6 (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 <[email protected]>
1 parent 49d04ff commit 75b23f9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

refs/files-backend.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3265,7 +3265,13 @@ static int files_transaction_finish(struct ref_store *ref_store,
32653265
* next update. If not, we try and create a regular symref.
32663266
*/
32673267
if (update->new_target && refs->prefer_symlink_refs)
3268-
if (!create_ref_symlink(lock, update->new_target))
3268+
/*
3269+
* By using the `NOT_CONSTANT()` trick, we can avoid
3270+
* errors by `clang`'s `-Wunreachable` logic that would
3271+
* report that the `continue` statement is not reachable
3272+
* when `NO_SYMLINK_HEAD` is `#define`d.
3273+
*/
3274+
if (NOT_CONSTANT(!create_ref_symlink(lock, update->new_target)))
32693275
continue;
32703276

32713277
if (update->flags & REF_NEEDS_COMMIT) {

0 commit comments

Comments
 (0)