diff --git a/docs/dev/clang-tidy-fixes-2026-04.md b/docs/dev/clang-tidy-fixes-2026-04.md index ec44f4dcd..8af7344e6 100644 --- a/docs/dev/clang-tidy-fixes-2026-04.md +++ b/docs/dev/clang-tidy-fixes-2026-04.md @@ -101,7 +101,8 @@ - [x] [modernize-avoid-c-arrays](https://clang.llvm.org/extra/clang-tidy/checks/modernize/avoid-c-arrays.html) (17) - _a.k.a._ [cppcoreguidelines-avoid-c-arrays](https://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/avoid-c-arrays.html) - [PR #745](https://github.com/Framework-R-D/phlex/pull/745) -- [ ] [modernize-avoid-c-style-cast](https://clang.llvm.org/extra/clang-tidy/checks/modernize/avoid-c-style-cast.html) (82) +- [x] [modernize-avoid-c-style-cast](https://clang.llvm.org/extra/clang-tidy/checks/modernize/avoid-c-style-cast.html) (82) + - [PR #771](https://github.com/Framework-R-D/phlex/pull/771) - [ ] [modernize-concat-nested-namespaces](https://clang.llvm.org/extra/clang-tidy/checks/modernize/concat-nested-namespaces.html) (1) - [x] [modernize-make-shared](https://clang.llvm.org/extra/clang-tidy/checks/modernize/make-shared.html) (1) - [PR #746](https://github.com/Framework-R-D/phlex/pull/746) diff --git a/form/root_storage/root_rfield_read_container.cpp b/form/root_storage/root_rfield_read_container.cpp index 1373e1e6d..72f84f797 100644 --- a/form/root_storage/root_rfield_read_container.cpp +++ b/form/root_storage/root_rfield_read_container.cpp @@ -79,8 +79,9 @@ namespace form::detail::experimental { createView(type); } - if (id >= (int)m_reader->GetNEntries()) + if (id >= static_cast(m_reader->GetNEntries())) { return false; + } //Using RNTupleView<> to read instead of reusing REntry gives us full schema evolution support: the ROOT feature that lets us read files with an old class version into a new class version's memory. auto buffer = m_view->GetField().CreateObject(); //PHLEX gets ownership of this memory diff --git a/form/storage/storage_reader.cpp b/form/storage/storage_reader.cpp index 4e77811d5..d327cae77 100644 --- a/form/storage/storage_reader.cpp +++ b/form/storage/storage_reader.cpp @@ -147,8 +147,7 @@ namespace { if (components.empty()) { return false; } - for (auto const& [key, value] : components) { - (void)key; + for (auto const& [_, value] : components) { if (value != 0) { return false; } @@ -356,8 +355,7 @@ std::vector StorageReader::listIndices( std::vector result; result.reserve(ordered.size()); - for (auto const& [entry, index_string] : ordered) { - (void)entry; + for (auto const& [_, index_string] : ordered) { result.push_back(index_string); } return result; diff --git a/phlex/model/index_generator.hpp b/phlex/model/index_generator.hpp index cf856b21e..9e66a681e 100644 --- a/phlex/model/index_generator.hpp +++ b/phlex/model/index_generator.hpp @@ -79,7 +79,7 @@ namespace phlex { return *this; } - void operator++(int) { (void)++(*this); } + void operator++(int) { ++(*this); } value_type const& operator*() const noexcept { return coroutine_.promise().current_; } value_type const* operator->() const noexcept diff --git a/phlex/utilities/resource_usage.cpp b/phlex/utilities/resource_usage.cpp index fe98ceeb5..18111b3a0 100644 --- a/phlex/utilities/resource_usage.cpp +++ b/phlex/utilities/resource_usage.cpp @@ -26,9 +26,9 @@ namespace { auto const [secs, microsecs] = used.ru_utime; // ru_maxrss is a POSIX field inside a GCC __extension__ union in ; // no user-controlled alternative exists. - return {.elapsed_time = double(secs) + (double(microsecs) / 1e6), + return {.elapsed_time = static_cast(secs) + (static_cast(microsecs) / 1e6), // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) - .max_rss = double(used.ru_maxrss) / mem_denominator}; + .max_rss = static_cast(used.ru_maxrss) / mem_denominator}; } } diff --git a/plugins/python/src/configwrap.cpp b/plugins/python/src/configwrap.cpp index ad4f6cb43..833822806 100644 --- a/plugins/python/src/configwrap.cpp +++ b/plugins/python/src/configwrap.cpp @@ -98,7 +98,7 @@ static PyObject* pcm_subscript(py_config_map* pycmap, PyObject* pykey) pyvalue = PyTuple_New(*cvalue_size); // We can use std::views::enumerate once the AppleClang C++ STL supports it. for (Py_ssize_t i = 0; i < *cvalue_size; ++i) { - PyObject* item = PyLong_FromLong((long)cvalue[i]); + PyObject* item = PyLong_FromLong(static_cast(cvalue[i])); PyTuple_SetItem(pyvalue, i, item); } } else if (k.first == boost::json::kind::int64) { @@ -148,8 +148,8 @@ static PyObject* pcm_subscript(py_config_map* pycmap, PyObject* pykey) pyvalue = PyTuple_New(*cvalue_size); // We can use std::views::enumerate once the AppleClang C++ STL supports it. for (Py_ssize_t i = 0; i < *cvalue_size; ++i) { - PyObject* item = - PyUnicode_FromStringAndSize(cvalue[i].c_str(), (Py_ssize_t)cvalue[i].size()); + PyObject* item = PyUnicode_FromStringAndSize(cvalue[i].c_str(), + static_cast(cvalue[i].size())); PyTuple_SetItem(pyvalue, i, item); } } else if (k.first == boost::json::kind::object) { @@ -164,8 +164,8 @@ static PyObject* pcm_subscript(py_config_map* pycmap, PyObject* pykey) for (Py_ssize_t i = 0; i < *cvalue_size; ++i) { PyObject* item = PyDict_New(); for (auto const& kv : cvalue[i]) { - PyObject* val = - PyUnicode_FromStringAndSize(kv.second.c_str(), (Py_ssize_t)kv.second.size()); + PyObject* val = PyUnicode_FromStringAndSize(kv.second.c_str(), + static_cast(kv.second.size())); PyDict_SetItemString(item, kv.first.c_str(), val); Py_DECREF(val); } @@ -178,7 +178,7 @@ static PyObject* pcm_subscript(py_config_map* pycmap, PyObject* pykey) } else { if (k.first == boost::json::kind::bool_) { auto cvalue = pycmap->ph_config->get(ckey); - pyvalue = PyBool_FromLong((long)cvalue); + pyvalue = PyBool_FromLong(static_cast(cvalue)); } else if (k.first == boost::json::kind::int64) { auto cvalue = pycmap->ph_config->get(ckey); // Note Python3.14 is expected to add PyLong_FromInt64 @@ -192,13 +192,14 @@ static PyObject* pcm_subscript(py_config_map* pycmap, PyObject* pykey) pyvalue = PyFloat_FromDouble(cvalue); } else if (k.first == boost::json::kind::string) { auto const& cvalue = pycmap->ph_config->get(ckey); - pyvalue = PyUnicode_FromStringAndSize(cvalue.c_str(), (Py_ssize_t)cvalue.size()); + pyvalue = + PyUnicode_FromStringAndSize(cvalue.c_str(), static_cast(cvalue.size())); } else if (k.first == boost::json::kind::object) { auto cvalue = pycmap->ph_config->get>(ckey); pyvalue = PyDict_New(); for (auto const& kv : cvalue) { - PyObject* val = - PyUnicode_FromStringAndSize(kv.second.c_str(), (Py_ssize_t)kv.second.size()); + PyObject* val = PyUnicode_FromStringAndSize(kv.second.c_str(), + static_cast(kv.second.size())); PyDict_SetItemString(pyvalue, kv.first.c_str(), val); Py_DECREF(val); } diff --git a/plugins/python/src/dciwrap.cpp b/plugins/python/src/dciwrap.cpp index bc75a211c..2baa1bc7f 100644 --- a/plugins/python/src/dciwrap.cpp +++ b/plugins/python/src/dciwrap.cpp @@ -27,7 +27,7 @@ PyObject* phlex::experimental::wrap_dci(data_cell_index const& dci) // simple forwarding methods static PyObject* dci_number(py_data_cell_index* pydci) { - return PyLong_FromLong((long)pydci->ph_dci->number()); + return PyLong_FromLong(static_cast(pydci->ph_dci->number())); } // PyMethodDef arrays must be non-const; tp_methods in PyTypeObject takes a non-const pointer. diff --git a/plugins/python/src/dyncall.cpp b/plugins/python/src/dyncall.cpp index 5892ddd95..e8a4fe067 100644 --- a/plugins/python/src/dyncall.cpp +++ b/plugins/python/src/dyncall.cpp @@ -110,7 +110,7 @@ void phlex::experimental::dyncall(void* fn, dcarg& result, dcargs_t& args, int v // because libffi is, and that yields a plethora of warnings from clang-tidy, // none of which warrant actual changes. // NOLINTBEGIN - std::size_t nargs = (std::size_t)args.size(); + std::size_t nargs = args.size(); auto t = std::make_unique(nargs); auto p = std::make_unique(nargs); diff --git a/plugins/python/src/modulewrap.cpp b/plugins/python/src/modulewrap.cpp index e8d33b0d7..c02cf07bc 100644 --- a/plugins/python/src/modulewrap.cpp +++ b/plugins/python/src/modulewrap.cpp @@ -177,7 +177,7 @@ namespace { PyGILRAII gil; dcarg result{nullptr}; - dyncall((void*)m_ccallback, result, argsv, 1); + dyncall(m_ccallback, result, argsv, 1); std::string error_msg; if (!result.get()) { @@ -227,7 +227,7 @@ namespace { argsv.reserve(sizeof...(Is)); (argsv.push_back(args), ...); - dyncall((void*)m_ccallback, result, argsv); + dyncall(m_ccallback, result, argsv); // TODO: error reporting? if constexpr (!std::is_void_v) { @@ -337,7 +337,7 @@ namespace { for (Py_ssize_t i = 0; i < len; ++i) { PyObject* item = items[i]; // borrowed reference if (!PyUnicode_Check(item)) { - PyErr_Format(PyExc_TypeError, "item %d must be a string", (int)i); + PyErr_Format(PyExc_TypeError, "item %d must be a string", static_cast(i)); break; } @@ -512,9 +512,9 @@ namespace { // fail to pass float -> bool; the problem is rounding (0.1 -> 0 -> False) if (!(l == 0 || l == 1) || PyFloat_Check(pyobject)) { PyErr_SetString(PyExc_ValueError, "boolean value should be bool, or integer 1 or 0"); - return (bool)-1; + return static_cast(-1); } - return (bool)l; + return static_cast(l); } long pylong_as_strictlong(PyObject* pyobject) @@ -535,7 +535,7 @@ namespace { } PyErr_SetString(PyExc_TypeError, "int/long conversion expects a signed integer object"); - return (long)-1; + return static_cast(-1); } unsigned long pylong_or_int_as_ulong(PyObject* pyobject) @@ -543,7 +543,7 @@ namespace { // convert to C++ unsigned long, with bounds checking, allow int -> ulong. if (PyFloat_Check(pyobject)) { PyErr_SetString(PyExc_TypeError, "can\'t convert float to unsigned long"); - return (unsigned long)-1; + return static_cast(-1); } // accept numpy unsigned integer scalars (uint8, uint16, uint32, uint64) @@ -557,14 +557,14 @@ namespace { } unsigned long ul = PyLong_AsUnsignedLong(pyobject); - if (ul == (unsigned long)-1 && PyErr_Occurred() && PyLong_Check(pyobject)) { + if (ul == static_cast(-1) && PyErr_Occurred() && PyLong_Check(pyobject)) { PyErr_Clear(); long i = PyLong_AS_LONG(pyobject); if (0 <= i) { - ul = (unsigned long)i; + ul = static_cast(i); } else { PyErr_SetString(PyExc_ValueError, "can\'t convert negative value to unsigned long"); - return (unsigned long)-1; + return static_cast(-1); } } @@ -805,7 +805,7 @@ static PyObject* parse_args(PyObject* args, } // set concurrency, or the default of serial if not set - nconcur = nconcur_ > 0 ? (concurrency)nconcur_ : concurrency::serial; + nconcur = nconcur_ > 0 ? concurrency(nconcur_) : concurrency::serial; // retrieve function name if (!pyname) { @@ -1042,7 +1042,7 @@ static PyObject* md_transform(py_phlex_module* mod, PyObject* args, PyObject* kw std::vector input_types; std::vector output_suffixes; std::vector output_types; - auto nconcur = (concurrency)-1; + concurrency nconcur(-1); PyObject* callable = parse_args( args, kwds, cname, input_selectors, input_types, output_suffixes, output_types, nconcur); @@ -1190,7 +1190,7 @@ static PyObject* md_observe(py_phlex_module* mod, PyObject* args, PyObject* kwds std::vector input_types; std::vector output_suffixes; std::vector output_types; - auto nconcur = (concurrency)-1; + concurrency nconcur(-1); PyObject* callable = parse_args( args, kwds, cname, input_selectors, input_types, output_suffixes, output_types, nconcur); diff --git a/plugins/python/src/pymodule.cpp b/plugins/python/src/pymodule.cpp index a437cada3..1204d4593 100644 --- a/plugins/python/src/pymodule.cpp +++ b/plugins/python/src/pymodule.cpp @@ -210,7 +210,7 @@ static bool initialize() // Python interpreter will not happen atm. static std::atomic gil_released{false}; if (!gil_released.exchange(true)) { - (void)PyEval_SaveThread(); // state not saved, as no place to restore + PyEval_SaveThread(); // state not saved, as no place to restore } return true; diff --git a/test/form/form_source_extra_types.cpp b/test/form/form_source_extra_types.cpp index 195c951b1..326f6f1ec 100644 --- a/test/form/form_source_extra_types.cpp +++ b/test/form/form_source_extra_types.cpp @@ -1,6 +1,8 @@ #include "form/form_source_type_registry.hpp" #include "phlex/module.hpp" +#include + using namespace phlex; namespace { @@ -23,9 +25,8 @@ namespace { } } -PHLEX_REGISTER_ALGORITHMS(m, config) +PHLEX_REGISTER_ALGORITHMS(m) { - (void)m; - (void)config; + std::ignore = m; register_extra_form_types_once(); } diff --git a/test/product_selecting.cpp b/test/product_selecting.cpp index 47940b831..efd4f0478 100644 --- a/test/product_selecting.cpp +++ b/test/product_selecting.cpp @@ -16,9 +16,12 @@ using namespace std::string_literals; namespace { // Provider functions - int provide_idx(data_cell_index const& dci) { return int(dci.number()); } + int provide_idx(data_cell_index const& dci) { return static_cast(dci.number()); } int provide_number(data_cell_index const&) { return 3; } - double provide_temperature(data_cell_index const& dci) { return double(dci.number()) * 100.0; } + double provide_temperature(data_cell_index const& dci) + { + return static_cast(dci.number()) * 100.0; + } std::string provide_name(data_cell_index const& dci) { return fmt::format("John the {}th", dci.number()); diff --git a/test/type_distinction.cpp b/test/type_distinction.cpp index 59d192f2e..0829f8fe0 100644 --- a/test/type_distinction.cpp +++ b/test/type_distinction.cpp @@ -24,7 +24,7 @@ namespace { auto triple(int x) { return 3 * x; } - auto square(int x) { return std::tuple{x * x, double((x * x) + 0.5)}; } + auto square(int x) { return std::tuple{x * x, ((x * x) + 0.5)}; } int id(int x) { return x; }