Skip to content

Replace every (void) cast with [[maybe_unused]] - #130

Open
petlenz wants to merge 1 commit into
mainfrom
style-no-void-casts
Open

Replace every (void) cast with [[maybe_unused]]#130
petlenz wants to merge 1 commit into
mainfrom
style-no-void-casts

Conversation

@petlenz

@petlenz petlenz commented Aug 2, 2026

Copy link
Copy Markdown
Member

Project style: (void) casts are out, [[maybe_unused]] is in. Sweeps all 61 sites on main.

The sites split into two kinds and get different treatments:

Unused variable / parameter (14 sites)[[maybe_unused]] moves to the declaration and the (void)x; line is deleted:

for ([[maybe_unused]] auto const &t : model.tangents()) { ... }
[[maybe_unused]] cas::expression_holder<cas::scalar_expression> const *x = nullptr;
[[maybe_unused]] inline auto diff_tensor_wrt_scalar(
    [[maybe_unused]] ... const &expr, [[maybe_unused]] ... const &arg)

Discarding a [[nodiscard]] return (47 sites) — an attribute cannot annotate an expression, so these become a named declaration:

EXPECT_THROW([[maybe_unused]] auto const discarded = m.emit_compute_function(),
             std::runtime_error);
[[maybe_unused]] auto const K = m.add_parameter("K", 1.0);

Discard variables are named after the symbol being declared where one exists (K, alpha, eps_p), discarded otherwise.

Two incidental cleanups found by the sweep:

  • src/targets/numsim_material.cpp(void)i; was dead; i is used two lines above as outputs[i]. Deleted rather than annotated.
  • tests/IntegrationTest.cpp — the natural name a for one discard collided with a lambda's for (auto const &a : args) under -Wshadow; renamed a_sv.

Verification: git grep '(void)' over *.cpp/*.h returns nothing. Debug build clean under -Werror (which has -Wshadow and -Wunused on), 298/298 unit tests, 337/338 ctest. The one ctest failure, NumSimMaterialEndToEnd.J2PathDependentRetainsPlasticStrainOnUnload, reproduces identically on unmodified main — pre-existing, not from this change.

Open PRs that add their own (void) sites (#120, #121, #122, #123, #127) get the same treatment on their branches separately.

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.

1 participant