Description
When building libvalkey v0.5.0 with -DNDEBUG -Werror, compilation fails in src/rdma.c:
src/rdma.c:1039:36: error: variable 'event' set but not used [-Werror=unused-but-set-variable]
1039 | struct epoll_event events[1], *event;
| ^~~~~
src/rdma.c:1038:18: error: unused variable 'ctx' [-Werror=unused-variable]
1038 | RdmaContext *ctx = c->privctx;
| ^~~
Root Cause
In the valkeyRdmaWaitConn function, both ctx and event are only used inside an assert() call:
event = &events[0];
assert(event->data.fd == ctx->cm_channel->fd);
When building with -DNDEBUG, the assert() macro is removed by the preprocessor, leaving both variables unused. Since the build uses -Werror, these warnings become fatal errors.
Suggested Fix
Add VALKEY_UNUSED (already defined in include/valkey/async.h and used elsewhere in the same file) to both variable declarations:
- RdmaContext *ctx = c->privctx;
- struct epoll_event events[1], *event;
+ VALKEY_UNUSED RdmaContext *ctx = c->privctx;
+ struct epoll_event events[1];
+ VALKEY_UNUSED struct epoll_event *event;
Reproducer
cmake . -B build -DCMAKE_BUILD_TYPE=Release -DENABLE_RDMA=1 -G Ninja
ninja -C build
NDEBUG is implicitly defined in CMake Release builds.
This issue was found while packaging for conda-forge: conda-forge/libvalkey-feedstock#15
Description
When building libvalkey v0.5.0 with
-DNDEBUG -Werror, compilation fails insrc/rdma.c:Root Cause
In the
valkeyRdmaWaitConnfunction, bothctxandeventare only used inside anassert()call:When building with
-DNDEBUG, theassert()macro is removed by the preprocessor, leaving both variables unused. Since the build uses-Werror, these warnings become fatal errors.Suggested Fix
Add
VALKEY_UNUSED(already defined ininclude/valkey/async.hand used elsewhere in the same file) to both variable declarations:Reproducer
cmake . -B build -DCMAKE_BUILD_TYPE=Release -DENABLE_RDMA=1 -G Ninja ninja -C buildNDEBUG is implicitly defined in CMake Release builds.
This issue was found while packaging for conda-forge: conda-forge/libvalkey-feedstock#15