Conversation
operator>> dispatches on whether the callback is an exception callback
or an SQL callback. A callable that is neither (a void() callable such
as `[] {}` or std::function<void()>) fell off the end of a function
returning SqlBinder&, which is undefined behaviour, and the callback
was silently dropped. Compilers only emitted -Wreturn-type.
Add a final else branch with a static_assert so such callbacks fail at
compile time with a clear message. Valid callbacks are unaffected.
Fixes drogonframework#2605
markm101
force-pushed
the
bugfix/2605-sqlbinder-missing-return
branch
from
September 26, 2026 05:22
e991de1 to
df34091
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2605.
Problem
SqlBinder::operator>>picks where to store a callback withif constexprontraits::isExceptCallback/traits::isSqlCallback. A callable that is neither (perFunctionTraits.h, avoid()callable such as[] {},std::function<void()>orvoid (*)()) falls off the end of a function returningSqlBinder &. That is undefined behaviour, the callback is silently dropped, and the only signal is-Wreturn-type. This is the path cppcheck reported.Fix
Add a final
elsebranch with astatic_assert, so such a callback fails to compile with a clear message:The assert depends on the template parameter, so it is only evaluated for callbacks that reach that branch; valid callbacks are unaffected. The trailing
return *this;keeps every path returning, which is what static analysers check. This follows the existingstatic_assertchecks for wrong callback types inCallbackHolder.Testing
drogon,db_testanddb_api_test(Apple Clang, macOS);db_testpasses against SQLite (124 assertions, 3 test cases).[] {}tooperator>>:mastercompiles with-Wreturn-type; this branch fails with the message above.FunctionTraitsplus the fixed operator compiles cleanly on GCC 9.3–13.2, Clang 11–17 and MSVC for the valid callback kinds, and rejects thevoid()case on all of them.void()callback tooperator>>.clang-formatproduces no changes.No unit test is added: the change only affects code that fails to compile, which the gtest suite can't express without extra compile-failure test plumbing.