Skip to content

Conversation

Mic92
Copy link
Member

@Mic92 Mic92 commented Jul 17, 2025

Summary

Fix clang-tidy warnings about calling virtual methods during object construction in:

  • S3BinaryCacheStoreImpl: Move getUri() calls from constructor to methods
  • LocalBinaryCacheStore: Move getBinaryCacheDir() call from initializer list to constructor body

Calling virtual methods in constructors is undefined behavior in C++ as the vtable may not be fully initialized yet.

Mic92 added 2 commits July 17, 2025 15:45
Move init() call from constructor to openStore() method to avoid calling
virtual methods during object construction. This prevents undefined
behavior when virtual methods are called before the object is fully
constructed.
Move init() call from constructor to openStore() method to avoid calling
virtual methods during object construction. This prevents undefined
behavior when virtual methods are called before the object is fully
constructed.
@Mic92 Mic92 requested a review from Ericson2314 as a code owner July 17, 2025 13:46
@github-actions github-actions bot added the store Issues and pull requests concerning the Nix store label Jul 17, 2025
Copy link
Member

@edolstra edolstra left a comment

Choose a reason for hiding this comment

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

We could also move the various init() methods into the constructors of their corresponding classes.

BTW, it looks like HttpBinaryCache::init() is currently not called anywhere?

@Mic92 Mic92 merged commit 4c95086 into NixOS:master Jul 17, 2025
12 checks passed
@Mic92 Mic92 deleted the clang-tidy-virtual-methods branch July 17, 2025 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
store Issues and pull requests concerning the Nix store
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants