[fix][client-cpp] Fix TypedMessageTest to use receiveAsync<T> template overload with decoder#580
Open
geniusjoe wants to merge 2 commits into
Open
Conversation
…e overload with decoder
There was a problem hiding this comment.
Pull request overview
Fixes TypedMessageTest.testReceive to use the correct typed Consumer::receiveAsync<T>(callback, decoder) overload so the callback receives a TypedMessage<T> without relying on non-portable implicit downcasting behavior (fixes build issues on GCC 8.x as described in #466).
Changes:
- Update
TypedMessageTest.testReceiveto callconsumer.receiveAsync<int>(..., intDecoder)instead of the untyped overload. - Simplify the async receive callback to assign the already-decoded
TypedMessage<int>directly.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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 #466
Master Issue: #149
Motivation
The
TypedMessageTest.testReceivetest was usingreceiveAsyncincorrectly. It called the untypedreceiveAsync(const ReceiveCallback&)overload (whereReceiveCallbackisstd::function<void(Result, const Message&)>), but the lambda's parameter was declared asconst TypedMessage<int>&— a derived class reference. Since the actual argument passed at runtime isconst Message&, this relies on an implicit downcast from base to derived, which is not guaranteed to work across compilers.GCC 11+ happens to be permissive about this implicit conversion when constructing
std::functionfrom a lambda (it does not strictly enforce contravariance on parameter types during type erasure), so the code compiled successfully. However, GCC 8.x does not accept this conversion, causing a compilation failure (see #466).The fix is to use the proper typed template overload
consumer.receiveAsync<int>(callback, intDecoder), which internally constructsTypedMessage<int>{msg, decoder}and passes it to the callback. This is both the intended API usage and portable across all GCC versions.Modifications
consumer.receiveAsync(...)toconsumer.receiveAsync<int>(..., intDecoder)to use the correct typed template overload.msg = receivedMsginstead of manually constructingTypedMessage<int>{receivedMsg, intDecoder}, since the decoder is now passed toreceiveAsync<T>and applied internally.Verifying this change
This change is already covered by existing tests, such as
TypedMessageTest.testReceivewhich validates the typed message receive flow includingreceiveAsync<int>.Documentation
doc-not-needed(This is a test fix only, no public API changes.)