git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] refs: forbid clang to complain about unreachable code

From
Patrick Steinhardt <ps@pks.im>
Date
Oct 10, 2025, 05:36 UTC
Message-ID
<aOibbUqe-gfal6sd@pks.im>
In-Reply-To
<xmqqzf9zddia.fsf@gitster.g>
On Thu, Oct 09, 2025 at 01:30:21PM -0700, Junio C Hamano wrote:
Show 32 quoted lines
> "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
> writes:
> 
> > From: Johannes Schindelin <johannes.schindelin@gmx.de>
> >
> > 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>
> > ---
> >     refs: forbid clang to complain about unreachable code
> >     
> >     Just upstreamin'
> 
> It may not be a bad idea to deprecate core.preferSymlinkRefs now and
> remove it at Git 3.0 boundary.  Some platforms may not be able to do
> symbolic links and use it to represent HEAD, but everybody should be
> able to create a small text file with a single line.
> 
> But until then, this is a very reasonable thing to do.

Agreed. I don't see any reason why anyone would like to use symbolic refs for this. The reading side for such symrefs may continue to exist for a while. But the writing side can go away.

Patrick
Previous: Junio C HamanoNext: Patrick Steinhardt
Message 3 of 7 in “refs: forbid clang to complain about unreachable code”
  1. refs: forbid clang to complain about unreachable codeJohannes Schindelin via GitGitGadget, Oct 9, 2025
  2. Junio C HamanoOct 9, 2025
  3. Patrick SteinhardtOct 10, 2025
  4. Patrick SteinhardtOct 10, 2025
  5. Johannes SchindelinOct 10, 2025
  6. Patrick SteinhardtOct 11, 2025
  7. Junio C HamanoOct 10, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.