[common_callbacks] fix make_confirmation_callback lifetime issue #4004
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.
The make_confirmation_callback function takes the key argument as const ref, meaning that it'll be bound to an existing QString when the arg is QString, but a temporary QString would be constructed and bound to it when the "key" is not a QString. This is fine during the make_confirmation_callback's scope since const& extend the lifetime of the temporary, but passing that "const&" to a capture list of a lambda that'll be executed later does not extend the lifetime, hence leading to undefined behavior.
I believe this was not causing any issues in release builds because of the optimization level. The compiler is probably inlining the whole thing, so the QString is directly constructed into the lambda's body. I could only trigger this while running the unit tests in Windows, built with the Debug configuration.
The patch fixes this issue by taking QString as a value and moving that into the lambda capture.
MULTI-1907