From 0e6fffa81177c7cf344d42921624d60dcf310d18 Mon Sep 17 00:00:00 2001 From: fanquake Date: Wed, 9 Sep 2026 11:34:03 +0100 Subject: [PATCH 1/3] refactor: remove unused code --- cmake/pthread_checks.cmake | 8 ++++---- example/init.h | 2 +- include/mp/proxy-types.h | 8 ++++---- include/mp/type-chrono.h | 4 ++-- include/mp/type-data.h | 4 ++-- include/mp/type-number.h | 14 +++++++------- include/mp/type-string.h | 4 ++-- include/mp/type-struct.h | 16 ++++++++-------- include/mp/type-vector.h | 2 +- test/mp/test/foo-types.h | 10 +++++----- 10 files changed, 36 insertions(+), 36 deletions(-) diff --git a/cmake/pthread_checks.cmake b/cmake/pthread_checks.cmake index 1208391b..c5e6d98b 100644 --- a/cmake/pthread_checks.cmake +++ b/cmake/pthread_checks.cmake @@ -12,7 +12,7 @@ cmake_push_check_state() set(CMAKE_REQUIRED_LIBRARIES Threads::Threads) check_cxx_source_compiles(" #include - int main(int argc, char** argv) + int main() { char thread_name[16]; return pthread_getname_np(pthread_self(), thread_name, sizeof(thread_name)); @@ -21,7 +21,7 @@ check_cxx_source_compiles(" check_cxx_source_compiles(" #include - int main(int argc, char** argv) + int main() { return pthread_setname_np(pthread_self(), \"%s\", (void*)\"name\"); }" @@ -30,7 +30,7 @@ check_cxx_source_compiles(" check_cxx_source_compiles(" #include #include - int main(int argc, char** argv) + int main() { uint64_t tid; pthread_threadid_np(nullptr, &tid); @@ -41,7 +41,7 @@ check_cxx_source_compiles(" check_cxx_source_compiles(" #include #include - int main(int argc, char** argv) + int main() { return pthread_getthreadid_np(); }" diff --git a/example/init.h b/example/init.h index 54e36da8..5710adf8 100644 --- a/example/init.h +++ b/example/init.h @@ -14,7 +14,7 @@ class Init public: virtual ~Init() = default; virtual std::unique_ptr makePrinter() { return nullptr; } - virtual std::unique_ptr makeCalculator(std::unique_ptr printer) { return nullptr; } + virtual std::unique_ptr makeCalculator(std::unique_ptr) { return nullptr; } }; #endif // EXAMPLE_INIT_H diff --git a/include/mp/proxy-types.h b/include/mp/proxy-types.h index 9822c121..16044ab3 100644 --- a/include/mp/proxy-types.h +++ b/include/mp/proxy-types.h @@ -210,7 +210,7 @@ struct ReadDestUpdate //! can only be used to disable ReadField() calls in certain contexts like //! std::optional and pointer contexts. template -bool CustomHasField(TypeList, InvokeContext& invoke_context, const Input& input) +bool CustomHasField(TypeList, InvokeContext&, const Input& input) { return input.has(); } @@ -233,7 +233,7 @@ void ThrowField(TypeList, InvokeContext& invoke_context, Input&& inpu //! be created directly. Rethrow as std::runtime_error so callers expecting it //! will still catch it. template -void ThrowField(TypeList, InvokeContext& invoke_context, Input&& input) +void ThrowField(TypeList, InvokeContext&, Input&& input) { auto data = input.get(); throw std::runtime_error(std::string(CharCast(data.begin()), data.size())); @@ -247,7 +247,7 @@ void ThrowField(TypeList, InvokeContext& invoke_context, Input&& //! way to represent them in Cap'n Proto and a null Data field is a convenient //! representation. template -bool CustomHasValue(InvokeContext& invoke_context, const Values&... value) +bool CustomHasValue(InvokeContext&, const Values&...) { return true; } @@ -459,7 +459,7 @@ struct ClientException struct BuildParams : IterateFieldsHelper { template - void handleField(InvokeContext& invoke_context, Params& params, ParamList) + void handleField(InvokeContext&, Params&, ParamList) { } diff --git a/include/mp/type-chrono.h b/include/mp/type-chrono.h index 94b0f1f4..d8114fab 100644 --- a/include/mp/type-chrono.h +++ b/include/mp/type-chrono.h @@ -13,7 +13,7 @@ namespace mp { //! Overload CustomBuildField and CustomReadField to serialize std::chrono //! parameters and return values as numbers. template -void CustomBuildField(TypeList>, Priority<1>, InvokeContext& invoke_context, Value&& value, +void CustomBuildField(TypeList>, Priority<1>, InvokeContext&, Value&& value, Output&& output) { static_assert(safe_less_equal(std::numeric_limits::lowest(), std::numeric_limits::lowest()), @@ -35,7 +35,7 @@ decltype(auto) CustomReadField(TypeList>, Pri //! The capnp field type must be an integer type with enough range to hold the //! time_since_epoch() count for the given Duration (e.g. Int64 for nanoseconds). template -void CustomBuildField(TypeList>, Priority<1>, InvokeContext& invoke_context, +void CustomBuildField(TypeList>, Priority<1>, InvokeContext&, Value&& value, Output&& output) { using Rep = typename Duration::rep; diff --git a/include/mp/type-data.h b/include/mp/type-data.h index 9110be91..69c7634e 100644 --- a/include/mp/type-data.h +++ b/include/mp/type-data.h @@ -29,7 +29,7 @@ concept IsByteSpan = //! blob types like uint256 or PKHash with data() and size() methods pointing to //! bytes. template -void CustomBuildField(TypeList, Priority<2>, InvokeContext& invoke_context, Value&& value, Output&& output) +void CustomBuildField(TypeList, Priority<2>, InvokeContext&, Value&& value, Output&& output) requires (std::is_same_v && IsByteSpan) { auto result = output.init(value.size()); @@ -37,7 +37,7 @@ requires (std::is_same_v && IsBy } template -decltype(auto) CustomReadField(TypeList, Priority<2>, InvokeContext& invoke_context, Input&& input, ReadDest&& read_dest) +decltype(auto) CustomReadField(TypeList, Priority<2>, InvokeContext&, Input&& input, ReadDest&& read_dest) requires (std::is_same_v && IsByteSpan) { using ByteType = decltype(std::span{std::declval().begin(), std::declval().end()})::element_type; diff --git a/include/mp/type-number.h b/include/mp/type-number.h index 7ad21e3a..6128c8ba 100644 --- a/include/mp/type-number.h +++ b/include/mp/type-number.h @@ -11,7 +11,7 @@ namespace mp { template requires std::is_enum_v -LocalType BuildPrimitive(InvokeContext& invoke_context, +LocalType BuildPrimitive(InvokeContext&, const Value& value, TypeList) { @@ -23,7 +23,7 @@ LocalType BuildPrimitive(InvokeContext& invoke_context, template requires (std::is_integral_v && !std::is_same_v, bool>) -LocalType BuildPrimitive(InvokeContext& invoke_context, +LocalType BuildPrimitive(InvokeContext&, const Value& value, TypeList) { @@ -35,7 +35,7 @@ LocalType BuildPrimitive(InvokeContext& invoke_context, } template -LocalType BuildPrimitive(InvokeContext& invoke_context, bool value, TypeList) +LocalType BuildPrimitive(InvokeContext&, bool value, TypeList) { static_assert(std::is_same_v, "capnp field type should be Bool for bool parameters. Fix the .capnp schema."); @@ -44,7 +44,7 @@ LocalType BuildPrimitive(InvokeContext& invoke_context, bool value, TypeList requires std::is_floating_point_v -LocalType BuildPrimitive(InvokeContext& invoke_context, +LocalType BuildPrimitive(InvokeContext&, const Value& value, TypeList) { @@ -57,7 +57,7 @@ template requires std::is_enum_v decltype(auto) CustomReadField(TypeList, Priority<1>, - InvokeContext& invoke_context, + InvokeContext&, Input&& input, ReadDest&& read_dest) { @@ -74,7 +74,7 @@ template requires std::is_integral_v decltype(auto) CustomReadField(TypeList, Priority<1>, - InvokeContext& invoke_context, + InvokeContext&, Input&& input, ReadDest&& read_dest) { @@ -89,7 +89,7 @@ template requires std::is_floating_point_v decltype(auto) CustomReadField(TypeList, Priority<1>, - InvokeContext& invoke_context, + InvokeContext&, Input&& input, ReadDest&& read_dest) { diff --git a/include/mp/type-string.h b/include/mp/type-string.h index d81d59ec..3a2ed30c 100644 --- a/include/mp/type-string.h +++ b/include/mp/type-string.h @@ -13,7 +13,7 @@ namespace mp { template void CustomBuildField(TypeList, Priority<1>, - InvokeContext& invoke_context, + InvokeContext&, Value&& value, Output&& output) { @@ -24,7 +24,7 @@ void CustomBuildField(TypeList, template decltype(auto) CustomReadField(TypeList, Priority<1>, - InvokeContext& invoke_context, + InvokeContext&, Input&& input, ReadDest&& read_dest) { diff --git a/include/mp/type-struct.h b/include/mp/type-struct.h index 10d7dbd2..9fa537da 100644 --- a/include/mp/type-struct.h +++ b/include/mp/type-struct.h @@ -26,10 +26,10 @@ void BuildOne(TypeList param, template requires (index == ProxyType::fields) -void BuildOne(TypeList param, - InvokeContext& invoke_context, - Output&& output, - Value&& value) +void BuildOne(TypeList, + InvokeContext&, + Output&&, + Value&&) { } @@ -63,10 +63,10 @@ void ReadOne(TypeList param, template requires (index == ProxyType::fields) -void ReadOne(TypeList param, - InvokeContext& invoke_context, - Input& input, - Value& value) +void ReadOne(TypeList, + InvokeContext&, + Input&, + Value&) { } diff --git a/include/mp/type-vector.h b/include/mp/type-vector.h index 7b5197ff..d5abd48f 100644 --- a/include/mp/type-vector.h +++ b/include/mp/type-vector.h @@ -19,7 +19,7 @@ void CustomBuildField(TypeList>, BuildList(TypeList(), invoke_context, output, value); } -inline static bool BuildPrimitive(InvokeContext& invoke_context, std::vector::const_reference value, TypeList) +inline static bool BuildPrimitive(InvokeContext&, std::vector::const_reference value, TypeList) { return value; } diff --git a/test/mp/test/foo-types.h b/test/mp/test/foo-types.h index 85c36349..95f0ba51 100644 --- a/test/mp/test/foo-types.h +++ b/test/mp/test/foo-types.h @@ -65,7 +65,7 @@ decltype(auto) CustomReadField(TypeList, Priority<1>, InvokeContext& } // namespace test template -bool CustomHasField(TypeList, InvokeContext& invoke_context, const Input& input) +bool CustomHasField(TypeList, InvokeContext&, const Input& input) { // Cap'n Proto C++ cannot distinguish null vs empty Data in List(Data), so // interpret empty Data as null for this specific type. @@ -81,28 +81,28 @@ inline void CustomBuildMessage(InvokeContext& invoke_context, builder.setMessage(src.message + " build"); } -inline void CustomReadMessage(InvokeContext& invoke_context, +inline void CustomReadMessage(InvokeContext&, const test::messages::FooMessage::Reader& reader, test::FooMessage& dest) { dest.message = std::string{reader.getMessage()} + " read"; } -inline void CustomBuildMessage(InvokeContext& invoke_context, +inline void CustomBuildMessage(InvokeContext&, const test::FooMutable& src, test::messages::FooMutable::Builder&& builder) { builder.setMessage(src.message + " build"); } -inline void CustomReadMessage(InvokeContext& invoke_context, +inline void CustomReadMessage(InvokeContext&, const test::messages::FooMutable::Reader& reader, test::FooMutable& dest) { dest.message = std::string{reader.getMessage()} + " read"; } -inline void CustomPassMessage(InvokeContext& invoke_context, +inline void CustomPassMessage(InvokeContext&, const test::messages::FooMutable::Reader& reader, test::messages::FooMutable::Builder builder, std::function&& fn) From fd75dc669648c18faf2bbae46134296823695c39 Mon Sep 17 00:00:00 2001 From: fanquake Date: Wed, 28 Oct 2026 10:55:50 +0000 Subject: [PATCH 2/3] refactor: use requires clauses instead of SFINAE enable parameters Replace the unused `enable` default parameters with C++20 requires clauses. --- include/mp/proxy-types.h | 3 ++- include/mp/type-message.h | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/include/mp/proxy-types.h b/include/mp/proxy-types.h index 16044ab3..11946ea0 100644 --- a/include/mp/proxy-types.h +++ b/include/mp/proxy-types.h @@ -624,7 +624,8 @@ struct ServerExcept : Parent //! Helper for CustomPassField below. Call Accessor::get method if it has one, //! otherwise return capnp::Void. template -decltype(auto) MaybeGet(Message&& message, decltype(Accessor::get(message))* enable = nullptr) +decltype(auto) MaybeGet(Message&& message) + requires requires { Accessor::get(message); } { return Accessor::get(message); } diff --git a/include/mp/type-message.h b/include/mp/type-message.h index b1cec13d..25a39226 100644 --- a/include/mp/type-message.h +++ b/include/mp/type-message.h @@ -13,8 +13,8 @@ namespace mp { //! CustomBuildField overload because it only requires defining a normal //! function, not a template function, but less flexible. template -void CustomBuildField(TypeList, Priority<2>, InvokeContext& invoke_context, Value&& value, Output&& output, - decltype(CustomBuildMessage(invoke_context, value, std::move(output.get())))* enable = nullptr) +void CustomBuildField(TypeList, Priority<2>, InvokeContext& invoke_context, Value&& value, Output&& output) + requires requires { CustomBuildMessage(invoke_context, value, std::move(output.get())); } { CustomBuildMessage(invoke_context, value, std::move(output.init())); } @@ -25,9 +25,8 @@ void CustomBuildField(TypeList, Priority<2>, InvokeContext& invoke_co //! function, not a template function, but less flexible. template decltype(auto) CustomReadField(TypeList, Priority<2>, InvokeContext& invoke_context, Input&& input, - ReadDest&& read_dest, - decltype(CustomReadMessage(invoke_context, input.get(), - std::declval()))* enable = nullptr) + ReadDest&& read_dest) + requires requires { CustomReadMessage(invoke_context, input.get(), std::declval()); } { return read_dest.update([&](auto& value) { if (CustomHasField(TypeList(), invoke_context, input)) CustomReadMessage(invoke_context, input.get(), value); }); } @@ -35,7 +34,8 @@ decltype(auto) CustomReadField(TypeList, Priority<2>, InvokeContext& //! Helper for CustomPassField below. Call Accessor::init method if it has one, //! otherwise do nothing. template -decltype(auto) MaybeInit(Message&& message, decltype(Accessor::get(message))* enable = nullptr) +decltype(auto) MaybeInit(Message&& message) + requires requires { Accessor::get(message); } { return Accessor::init(message); } From ee8e64b87bca22b024fb52949b54185df8a76d96 Mon Sep 17 00:00:00 2001 From: fanquake Date: Wed, 9 Sep 2026 11:35:03 +0100 Subject: [PATCH 3/3] ci: add -Wunused to CI configs Along with -Wunused-const-variable. --- ci/configs/default.bash | 2 +- ci/configs/freebsd.bash | 2 +- ci/configs/gnu32.bash | 2 +- ci/configs/llvm.bash | 2 +- ci/configs/macos.bash | 2 +- ci/configs/netbsd.bash | 2 +- ci/configs/newdeps.bash | 2 +- ci/configs/olddeps.bash | 2 +- ci/configs/openbsd.bash | 2 +- ci/configs/sanitize.bash | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ci/configs/default.bash b/ci/configs/default.bash index 492992c6..5cce6d3c 100644 --- a/ci/configs/default.bash +++ b/ci/configs/default.bash @@ -1,5 +1,5 @@ CI_DESC="CI job using default libraries and tools, and running IWYU" CI_DIR=build-default -export CXXFLAGS="-Werror -Wall -Wextra -Wpedantic -Wundef -Wunused-const-variable -Wno-unused-parameter -Wextra-semi -Wmissing-noreturn -Wtrailing-whitespace" +export CXXFLAGS="-Werror -Wall -Wextra -Wpedantic -Wundef -Wunused -Wunused-const-variable -Wextra-semi -Wmissing-noreturn -Wtrailing-whitespace" CMAKE_ARGS=(-DMP_ENABLE_IWYU=ON) BUILD_ARGS=(-k) diff --git a/ci/configs/freebsd.bash b/ci/configs/freebsd.bash index 096e2649..ca788c31 100644 --- a/ci/configs/freebsd.bash +++ b/ci/configs/freebsd.bash @@ -1,5 +1,5 @@ CI_DESC="CI config for FreeBSD" CI_DIR=build-freebsd -export CXXFLAGS="-Werror -Wall -Wextra -Wpedantic -Wno-unused-parameter -Wno-c++23-lambda-attributes" +export CXXFLAGS="-Werror -Wall -Wextra -Wpedantic -Wunused -Wunused-const-variable -Wno-c++23-lambda-attributes" CMAKE_ARGS=(-G Ninja) BUILD_ARGS=(-k 0) diff --git a/ci/configs/gnu32.bash b/ci/configs/gnu32.bash index 3d63360f..b88cd450 100644 --- a/ci/configs/gnu32.bash +++ b/ci/configs/gnu32.bash @@ -6,6 +6,6 @@ NIX_ARGS=( --arg minimal true --arg crossPkgs 'import { crossSystem = { config = "i686-unknown-linux-gnu"; }; }' ) -export CXXFLAGS="-Werror -Wall -Wextra -Wpedantic -Wunused-const-variable -Wno-unused-parameter" +export CXXFLAGS="-Werror -Wall -Wextra -Wpedantic -Wunused -Wunused-const-variable" CMAKE_ARGS=(-G Ninja) BUILD_ARGS=(-k 0) diff --git a/ci/configs/llvm.bash b/ci/configs/llvm.bash index 4257db83..049dd09b 100644 --- a/ci/configs/llvm.bash +++ b/ci/configs/llvm.bash @@ -2,7 +2,7 @@ CI_DESC="CI job using LLVM-based libraries and tools (clang, libc++, clang-tidy, CI_DIR=build-llvm NIX_ARGS=(--arg enableLibcxx true) export CXX=clang++ -export CXXFLAGS="-Werror -Wall -Wextra -Wextra-semi -Wpedantic -Wundef -Wthread-safety -Wno-unused-parameter -Wno-c++23-lambda-attributes" +export CXXFLAGS="-Werror -Wall -Wextra -Wextra-semi -Wpedantic -Wundef -Wthread-safety -Wunused -Wunused-const-variable -Wno-c++23-lambda-attributes" CMAKE_ARGS=( -G Ninja -DMP_ENABLE_CLANG_TIDY=ON diff --git a/ci/configs/macos.bash b/ci/configs/macos.bash index 4c3a0fea..2770bc65 100644 --- a/ci/configs/macos.bash +++ b/ci/configs/macos.bash @@ -1,5 +1,5 @@ CI_DESC="CI config for macOS" CI_DIR=build-macos -export CXXFLAGS="-Werror -Wall -Wextra -Wpedantic -Wno-unused-parameter -Wno-c++23-lambda-attributes" +export CXXFLAGS="-Werror -Wall -Wextra -Wpedantic -Wunused -Wunused-const-variable -Wno-c++23-lambda-attributes" CMAKE_ARGS=(-G Ninja -DMP_ENABLE_CLANG_TIDY=ON) BUILD_ARGS=(-k 0) diff --git a/ci/configs/netbsd.bash b/ci/configs/netbsd.bash index 203b6623..74578602 100644 --- a/ci/configs/netbsd.bash +++ b/ci/configs/netbsd.bash @@ -1,5 +1,5 @@ CI_DESC="CI config for NetBSD" CI_DIR=build-netbsd -export CXXFLAGS="-Werror -Wall -Wextra -Wpedantic -Wno-unused-parameter ${CXXFLAGS:-}" +export CXXFLAGS="-Werror -Wall -Wextra -Wpedantic -Wunused -Wunused-const-variable ${CXXFLAGS:-}" CMAKE_ARGS=(-G Ninja) BUILD_ARGS=(-k 0) diff --git a/ci/configs/newdeps.bash b/ci/configs/newdeps.bash index c86a833d..076232ea 100644 --- a/ci/configs/newdeps.bash +++ b/ci/configs/newdeps.bash @@ -1,6 +1,6 @@ CI_DESC="CI job using newest Cap'n Proto and cmake versions" CI_DIR=build-newdeps -export CXXFLAGS="-Werror -Wall -Wextra -Wpedantic -Wunused-const-variable -Wno-unused-parameter -Wno-error=array-bounds" +export CXXFLAGS="-Werror -Wall -Wextra -Wpedantic -Wunused -Wunused-const-variable -Wno-error=array-bounds" CAPNP_CHECKOUT=master # This is the v1.x release branch NIX_ARGS=(--argstr capnprotoVersion "none" --argstr cmakeVersion "4.3.4") BUILD_ARGS=(-k) diff --git a/ci/configs/olddeps.bash b/ci/configs/olddeps.bash index 81d084fc..b2bc08b0 100644 --- a/ci/configs/olddeps.bash +++ b/ci/configs/olddeps.bash @@ -2,7 +2,7 @@ CI_DESC="CI job using old Cap'n Proto and cmake versions" CI_DIR=build-olddeps # Pin olddeps to an older Nixpkgs channel, to be able to test an older GCC. CI_NIXPKGS_CHANNEL=nixos-25.05 -export CXXFLAGS="-Werror -Wall -Wextra -Wpedantic -Wunused-const-variable -Wno-unused-parameter -Wno-error=array-bounds" +export CXXFLAGS="-Werror -Wall -Wextra -Wpedantic -Wunused -Wunused-const-variable -Wno-error=array-bounds" CAPNP_CHECKOUT=v0.9.2 # Use a checkout to compile it with the selected GCC NIX_ARGS=(--argstr capnprotoVersion "none" --argstr cmakeVersion "3.12.4" --argstr gccVersion "10") BUILD_ARGS=(-k) diff --git a/ci/configs/openbsd.bash b/ci/configs/openbsd.bash index 276ef17a..9ebf81f0 100644 --- a/ci/configs/openbsd.bash +++ b/ci/configs/openbsd.bash @@ -3,6 +3,6 @@ CI_DIR=build-openbsd # The -Wno-c2y-extensions flag can be dropped once the change # from commit 3724713e82456ce7d66d1f377539dd2e142d969a becomes # available in Clang. -export CXXFLAGS="-Werror -Wall -Wextra -Wpedantic -Wno-unused-parameter -Wno-c++23-lambda-attributes -Wno-c2y-extensions" +export CXXFLAGS="-Werror -Wall -Wextra -Wpedantic -Wunused -Wunused-const-variable -Wno-c++23-lambda-attributes -Wno-c2y-extensions" CMAKE_ARGS=(-G Ninja) BUILD_ARGS=(-k 0) diff --git a/ci/configs/sanitize.bash b/ci/configs/sanitize.bash index 907f3295..109ea2d8 100644 --- a/ci/configs/sanitize.bash +++ b/ci/configs/sanitize.bash @@ -2,7 +2,7 @@ CI_DESC="CI job running ThreadSanitizer" CI_DIR=build-sanitize NIX_ARGS=(--arg enableLibcxx true --argstr libcxxSanitizers "Thread" --argstr capnprotoSanitizers "thread") export CXX=clang++ -export CXXFLAGS="-ggdb -Werror -Wall -Wextra -Wpedantic -Wthread-safety -Wno-unused-parameter -fsanitize=thread -Wno-c++23-lambda-attributes" +export CXXFLAGS="-ggdb -Werror -Wall -Wextra -Wpedantic -Wthread-safety -Wunused -Wunused-const-variable -fsanitize=thread -Wno-c++23-lambda-attributes" CMAKE_ARGS=() BUILD_ARGS=(-k) BUILD_TARGETS=(mptest)