Skip to content

Conversation

@mhucka
Copy link
Collaborator

@mhucka mhucka commented Nov 4, 2025

The compiler is generating false positives. The solution (which is actually the work of @sergeisakov, via offline communications) involves slightly refactoring the code in a way that avoids creating a temporary vector.

The problem that lead to the compiler warnings is that
`discarded_results` in `ApplyFusedGate` is passed by value to the inner
`ApplyFusedGate`. When `std::move(measure_result)` happens inside, it's
moving from a stack object into a vector that is also on the stack
(because it's a parameter passed by value). Then when the inner
`ApplyFusedGate` returns, its copy of `mresults` is destroyed,
triggering the warning.

The solution used here is to refactor the logic into a separate
implementation function that accepts a pointer to the results vector.
This pointer can be `nullptr` to explicitly signal that measurement
results should be discarded. This change eliminates the temporary
`discarded_results` vector. Since the vector is never created, its
destructor is never called, and the compiler warning vanishes. This is
also faster, as you save the cost of constructing and destructing that
temporary vector.
@github-actions github-actions bot added the size: M 50< lines changed <250 label Nov 4, 2025
@mhucka mhucka marked this pull request as ready for review November 4, 2025 07:21
@mhucka mhucka requested a review from sergeisakov November 4, 2025 07:22
Sergei provided a better solution; it involves some mild refactoring.
Also, he pointed out that there is a second very similar function in
the file that should be changed in the same way.
@github-actions github-actions bot added size: S 10< lines changed <50 and removed size: M 50< lines changed <250 labels Nov 4, 2025
@mhucka mhucka enabled auto-merge November 4, 2025 19:39
@mhucka mhucka added this pull request to the merge queue Nov 4, 2025
Merged via the queue into quantumlib:main with commit 9654999 Nov 4, 2025
52 checks passed
@mhucka mhucka deleted the mh-fix-935 branch November 4, 2025 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: S 10< lines changed <50

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants