Skip to content

Use unreachable in nix::listNarImpl()#14944

Merged
xokdvium merged 1 commit intoNixOS:masterfrom
iljah:patch-2
Feb 9, 2026
Merged

Use unreachable in nix::listNarImpl()#14944
xokdvium merged 1 commit intoNixOS:masterfrom
iljah:patch-2

Conversation

@iljah
Copy link
Contributor

@iljah iljah commented Jan 7, 2026

Prevent

../src/libutil/nar-accessor.cc: In function ”nix::ListNarResult<deep> nix::listNarImpl(SourceAccessor&, const CanonPath&) [with bool deep = true]”:
../src/libutil/nar-accessor.cc:335:1: varoitus: ei-void-tyyppisen funktion loppu saavutettu [-Wreturn-type]
  335 | }
      | ^
../src/libutil/nar-accessor.cc: In function ”nix::ListNarResult<deep> nix::listNarImpl(SourceAccessor&, const CanonPath&) [with bool deep = false]”:
../src/libutil/nar-accessor.cc:335:1: varoitus: ei-void-tyyppisen funktion loppu saavutettu [-Wreturn-type]

Motivation

Context


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@iljah iljah requested a review from edolstra as a code owner January 7, 2026 16:53
Copy link
Member

@Ericson2314 Ericson2314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call unreachable() because the switch is supposed to be exhaustive. The fact that only some compilers give this error and not others makes me wonder if we can fix it with compiler flags too

@iljah iljah changed the title Return value from nix::listNarImpl() Use unreachable in nix::listNarImpl() Jan 8, 2026
@iljah
Copy link
Contributor Author

iljah commented Jan 8, 2026

Thanks, switched to unreachable().

@xokdvium
Copy link
Contributor

xokdvium commented Jan 8, 2026

Generally, we prefer nix::unreachable() because it doesn't invoke UB and just fails at runtime unlike std::unreachable. It's also marked [[noreturn]], so it should silence the diagnostic.

@Ericson2314
Copy link
Member

Can you rebase and squash?

Prevent
```
../src/libutil/nar-accessor.cc: In function ”nix::ListNarResult<deep> nix::listNarImpl(SourceAccessor&, const CanonPath&) [with bool deep = true]”:
../src/libutil/nar-accessor.cc:335:1: varoitus: ei-void-tyyppisen funktion loppu saavutettu [-Wreturn-type]
  335 | }
      | ^
../src/libutil/nar-accessor.cc: In function ”nix::ListNarResult<deep> nix::listNarImpl(SourceAccessor&, const CanonPath&) [with bool deep = false]”:
../src/libutil/nar-accessor.cc:335:1: varoitus: ei-void-tyyppisen funktion loppu saavutettu [-Wreturn-type]
```
@xokdvium
Copy link
Contributor

xokdvium commented Feb 7, 2026

Added a throw instead. That should be cheap and more correct in the long run anyway.

@xokdvium xokdvium dismissed Ericson2314’s stale review February 7, 2026 14:40

No longer relevant, since it's an exception instead of unreachable now.

@xokdvium xokdvium added this pull request to the merge queue Feb 9, 2026
Merged via the queue into NixOS:master with commit 36ad296 Feb 9, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants