Conversation
…les` - Audit all occurrences - Fix unnecessary occurrence in `test/type_deduction.cpp` - Add justification comments and ignore via `NOLINT*` annotations
There was a problem hiding this comment.
Pull request overview
Resolves clang-tidy findings from cppcoreguidelines-avoid-non-const-global-variables by making one unnecessary test-global const and documenting/suppressing the remaining intentional non-const globals introduced by plugin-registration macros and Python C-API requirements.
Changes:
- Make the
type_deductiontest’s global closureconst. - Add targeted
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)suppressions with justification for intentional non-const globals in tests/plugins. - Add similar suppressions/justifications for required non-const Python C-API globals (
PyTypeObject,PyMethodDef,PyMappingMethods) in the Python plugin code.
Reviewed changes
Copilot reviewed 35 out of 35 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/type_deduction.cpp | Makes the file-scope lambda closure const to avoid the non-const global warning. |
| test/replicated.cpp | Documents and suppresses the intentional non-const global atomic counter used across concurrent callbacks. |
| test/python/source.cpp | Suppresses macro-introduced non-const global created by plugin registration. |
| test/plugins/output.cpp | Suppresses macro-introduced non-const global created by plugin registration. |
| test/plugins/module.cpp | Suppresses macro-introduced non-const global created by plugin registration. |
| test/plugins/ij_source.cpp | Suppresses macro-introduced non-const global created by plugin registration. |
| test/mock-workflow/three_tuple_algorithm.cpp | Suppresses macro-introduced non-const global created by plugin registration. |
| test/mock-workflow/pd_fast_sim.cpp | Suppresses macro-introduced non-const global created by plugin registration. |
| test/mock-workflow/largeant.cpp | Suppresses macro-introduced non-const global created by plugin registration. |
| test/mock-workflow/ion_and_scint.cpp | Suppresses macro-introduced non-const global created by plugin registration. |
| test/mock-workflow/id_provider.cpp | Suppresses macro-introduced non-const global created by plugin registration. |
| test/mock-workflow/MC_truth_algorithm.cpp | Suppresses macro-introduced non-const global created by plugin registration. |
| test/max-parallelism/provide_parallelism.cpp | Suppresses macro-introduced non-const global created by plugin registration. |
| test/max-parallelism/check_parallelism.cpp | Suppresses macro-introduced non-const global created by plugin registration. |
| test/benchmarks/verify_even_fibonacci_numbers.cpp | Suppresses macro-introduced non-const global created by plugin registration. |
| test/benchmarks/verify_difference.cpp | Suppresses macro-introduced non-const global created by plugin registration. |
| test/benchmarks/read_index.cpp | Suppresses macro-introduced non-const global created by plugin registration. |
| test/benchmarks/read_id.cpp | Suppresses macro-introduced non-const global created by plugin registration. |
| test/benchmarks/plus_one.cpp | Suppresses macro-introduced non-const global created by plugin registration. |
| test/benchmarks/plus_101.cpp | Suppresses macro-introduced non-const global created by plugin registration. |
| test/benchmarks/last_index.cpp | Suppresses macro-introduced non-const global created by plugin registration. |
| test/benchmarks/benchmarks_provider.cpp | Suppresses macro-introduced non-const global created by plugin registration. |
| test/benchmarks/accept_fibonacci_numbers.cpp | Suppresses macro-introduced non-const global created by plugin registration. |
| test/benchmarks/accept_even_numbers.cpp | Suppresses macro-introduced non-const global created by plugin registration. |
| test/benchmarks/accept_even_ids.cpp | Suppresses macro-introduced non-const global created by plugin registration. |
| plugins/python/src/wrap.hpp | Adds justification + suppression for exported non-const PyTypeObject declarations required by Python C API. |
| plugins/python/src/pymodule.cpp | Suppresses macro-introduced non-const globals created by plugin registration inside separate namespaces. |
| plugins/python/src/modulewrap.cpp | Suppresses required non-const PyMethodDef arrays and PyTypeObject definitions used by Python C API. |
| plugins/python/src/lifelinewrap.cpp | Suppresses required non-const PyTypeObject definition used by Python C API. |
| plugins/python/src/dciwrap.cpp | Suppresses required non-const PyMethodDef array and PyTypeObject definition used by Python C API. |
| plugins/python/src/configwrap.cpp | Suppresses required non-const PyMappingMethods and PyTypeObject used by Python C API. |
| plugins/generate_layers.cpp | Suppresses macro-introduced non-const global created by driver registration. |
| phlex/app/load_module.cpp | Suppresses intentional file-scope non-const globals that retain plugin factory callables to prevent unloading. |
| form/form_module.cpp | Suppresses macro-introduced non-const global created by plugin registration. |
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #544 +/- ##
==========================================
- Coverage 86.74% 85.62% -1.13%
==========================================
Files 142 143 +1
Lines 5033 3665 -1368
Branches 631 631
==========================================
- Hits 4366 3138 -1228
+ Misses 452 313 -139
+ Partials 215 214 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 108 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
clang-tidy: resolve cppcoreguidelines-avoid-non-const-global-variblesclang-tidy: resolve cppcoreguidelines-avoid-non-const-global-variables
The clang-tidy check cppcoreguidelines-avoid-non-const-global-variables
fired at every PHLEX_REGISTER_ALGORITHMS, PHLEX_REGISTER_PROVIDERS, and
PHLEX_REGISTER_DRIVER call site because BOOST_DLL_ALIAS — which those
macros previously expanded to — creates a const-pointer-to-void alias
variable at namespace scope. A pointer-to-const is not a const object,
so the check fires. Suppressing it with a per-site NOLINTNEXTLINE forced
every user of those macros (plugins, sources, tests) to carry an
explanation comment they did not write and had nothing to do with.
Root-cause fix
--------------
Replace BOOST_DLL_ALIAS with direct symbol export:
* Modules / sources (PHLEX_REGISTER_ALGORITHMS, PHLEX_REGISTER_PROVIDERS):
The macro now expands to a single extern "C" function definition named
after the DLL alias token. boost::dll::import_symbol<T> can find a
function by name directly; no intermediate alias variable is needed.
The forwarding declaration that preceded BOOST_DLL_ALIAS is removed
because the entry-point function is now defined in one step.
* Driver (PHLEX_REGISTER_DRIVER):
The driver entry-point cannot use extern "C" with a direct return type
because driver_bundle is a C++ type and the compiler rejects
-Wreturn-type-c-linkage. Instead the macro now:
1. Forward-declares the user's C++ implementation.
2. Defines a thin extern "C" void shim that accepts the same proxy
and config arguments plus a driver_bundle* out-parameter, calls
the C++ implementation, and writes the result through the pointer.
3. Opens the user's C++ implementation definition for the body that
follows the macro.
The shim has a void return type and C-compatible parameter types, so
no linkage warning is triggered.
Loader changes (load_module.cpp)
---------------------------------
* import_alias<T> is replaced with import_symbol<T> throughout.
import_alias reads a void* variable; import_symbol resolves a function
directly by name, matching the new extern "C" export scheme.
* create_driver's stored type changes from
std::function<detail::driver_creator_t> to
std::function<detail::driver_shim_t> to match the shim signature.
* The driver invocation is updated to pass an out-parameter:
driver_bundle result;
create_driver(proxy, config, &result);
return result;
Supporting type alias (driver.hpp)
-----------------------------------
detail::driver_shim_t is added alongside the existing driver_creator_t:
using driver_shim_t = void(driver_proxy const&, configuration const&, driver_bundle*);
The include of boost/dll/alias.hpp is removed from driver.hpp, module.hpp,
and source.hpp; those headers no longer need it.
Call-site cleanup (26 files)
------------------------------
Every PHLEX_REGISTER_* call site previously carried:
// BOOST_DLL_ALIAS creates a non-const exported function pointer; ...
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
Both lines are removed from all 26 affected files because the macro no
longer produces any non-const global variable.
All 85 tests continue to pass.
test/type_deduction.cppNOLINT*annotations