[cpp] Avoid temporary flecs::term objects in query builder with() methods - #2193
Open
AnonimiAngels wants to merge 1 commit into
Open
Conversation
…hods The with() overloads constructed a temporary flecs::term just to copy its value into the query descriptor. Term objects store pointers to their own stack memory (term_/term_ref_), so assigning a temporary to the descriptor gets reported by static analyzers as an escaping stack address (clang-analyzer core.StackAddressEscape), even though only the pointer-free ecs_term_t value is copied. Write the term value directly instead. This produces identical term values, removes the analyzer report at the source, and skips the temporary's construction, conversion copy and virtual destructor.
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.
The
with()overloads inquery_builder_iconstruct a temporaryflecs::termjust to copy its value into the query descriptor. Term objects store pointers to their own stack memory (term_/term_ref_point at the object's ownvaluemember), so the assignment gets reported by clang's static analyzer as an escaping stack address (clang-analyzer-core.StackAddressEscape, anchored atbuilder_i.hpp:77). It is a false positive — only the pointer-freeecs_term_tvalue is copied — but it fires in any downstream project that runs clang-tidy over code that instantiates a query builder (world.each, query/system/observer builders), and it cannot be suppressed downstream without disabling the checker.This writes the term value directly instead of going through the temporary:
$name-to-variable handling is reused through the inheritedfirst()/second().with(flecs::term&)/with(flecs::term&&)are unchanged (caller-owned objects, no temporary involved).with()call.distr/contains the same change.Tested with
bake run test/queryandbake run test/cpp(all green), anddistr/flecs.ccompiles with the CI flag set (clang -Werror -Wshadow -Wconversion ...). Also verified in a downstream C++26 project running clang-tidy 22 withclang-analyzer-*promoted to errors: the report disappears at the source and the full build stays green.