Skip to content

build: clean the warning set and enforce it in CI (#76) - #86

Open
petlenz wants to merge 1 commit into
mainfrom
fix/hygiene
Open

petlenz wants to merge 1 commit into
mainfrom
fix/hygiene

Conversation

@petlenz

@petlenz petlenz commented Sep 20, 2026

Copy link
Copy Markdown
Member

Closes #76.

The library warnings

-Wreorder linear_elasticity.h: m_eps_name was declared after m_K/m_G but initialized before them, and m_eps is wired from it. Members initialize in declaration order regardless of how the initializer list reads, so this worked only by luck of m_eps being last.
-Wshadow x2 material_base.h: two constructor parameters named after the type aliases they shadow.
unused typedef json_material_factory.h

Plus [[nodiscard]] on local_newton::solve and vector_newton::converged (backward_euler already had it) -- a dropped convergence flag is the bug this codebase has had most often -- and the dead m_material_handler, confirmed unread across include, tests and examples. The constructor parameter stays, since object_store passes it.

Why SYSTEM includes were needed first

I added -Werror for the cleaned classes, then found every remaining warning came from tmech, dozens of -Wshadow among them. As written, the CI change would have failed on a dependency we do not control, on its first run.

tmech, nlohmann and Eigen are now SYSTEM includes. Their warnings were never ours to act on, and they were burying the three that were.

The gate found nine more, in our tests

Local aliases duplicating the file-scope one, an unused handle, and an unbraced if around EXPECT_NEAR -- which expands to an if/else, so it was a genuine dangling else.

The tensor2 in test_j2_plasticity is not redundant: the file-scope one is fixed at 3 while that one is parameterized on Dim. Renamed rather than removed.

One fix nearly introduced a bug

This is the argument for the gate. test_statev_map.cpp had:

tmech::tensor<T, 3, 4> isotropic4(T K, T G) {   // shadows file-scope K, G
  C = 3.0 * K * IIvol + 2.0 * G * (IIsym - IIvol);

Renaming the parameters to bulk/shear left the body reading K and G, which silently rebound to the file-scope constants 166.67/76.92 -- the function would have ignored its arguments entirely. Caught on inspection and repointed.

The only caller passes exactly those values, so no test outcome would have changed either way. That is luck, not correctness, and it is precisely what -Wshadow is for.

CI

-Wall -Wextra -Wshadow -Wreorder, with -Werror for the three cleaned classes only. Deliberately not a blanket -Werror, which would fail on any new warning class a future compiler adds.

300/300 with -Werror active.

Note on overlap

This touches CMakeLists.txt (the target_include_directories lines) and #81 touches it too (the install section). They should merge cleanly; I will verify the merge result locally before either lands rather than assume it.

Three warning sites in the library, plus the leftovers from the review.

  -Wreorder   linear_elasticity.h: m_eps_name was declared after m_K/m_G
              but initialized before them, and m_eps is wired FROM it.
              Members initialize in declaration order regardless of how the
              initializer list reads, so this worked by luck of m_eps being
              last. Declarations now match the list.
  -Wshadow    material_base.h: two constructor parameters named after the
              type aliases they shadow.
  unused      json_material_factory.h: a typedef nothing read.

[[nodiscard]] on local_newton::solve and vector_newton::converged, which
backward_euler already had. A dropped convergence flag is the bug this
codebase has had most often.

material_base::m_material_handler was stored and never read -- confirmed
across include, tests and examples. The constructor parameter stays,
because object_store passes it.

tmech, nlohmann and Eigen become SYSTEM includes. Their warnings were
never ours to act on and they were burying the three that were: tmech
alone emits dozens of -Wshadow. This is what makes -Werror possible at
all -- without it the CI gate below would have failed on a dependency we
do not control, on its first run.

With the gate on, it immediately found nine more in our own TESTS: local
aliases duplicating the file-scope one, an unused handle, and an unbraced
if around EXPECT_NEAR (which expands to an if/else, so it was a real
dangling else). The Dim-parameterized `tensor2` in test_j2_plasticity is
NOT redundant -- the file-scope one is fixed at 3 -- so it is renamed
rather than removed.

One of those fixes nearly introduced a bug, which is the argument for the
gate. test_statev_map's isotropic4(T K, T G) shadowed the file-scope K and
G; renaming the parameters left the body reading K and G, which silently
rebound to the file-scope constants, so the function would have ignored
its arguments. The only caller passes exactly those values, so no test
outcome would have changed -- luck, not correctness.

CI now builds with -Wall -Wextra -Wshadow -Wreorder and -Werror for the
three cleaned classes. Not a blanket -Werror: that would fail on any new
warning class the compiler adds.

300/300 with -Werror active.
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.

Hygiene: compiler warnings, missing [[nodiscard]], dead members

1 participant