Pass decomposition expr to a lambda instead of storing it to a local#160
Open
sarah-quinones wants to merge 1 commit intojeremy-rifkin:mainfrom
Open
Pass decomposition expr to a lambda instead of storing it to a local#160sarah-quinones wants to merge 1 commit intojeremy-rifkin:mainfrom
sarah-quinones wants to merge 1 commit intojeremy-rifkin:mainfrom
Conversation
41cb044 to
e45fb13
Compare
…so that intermediate lifetimes are not ended too soon
e45fb13 to
72e5a65
Compare
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.
i first ran into this bug while using libassert with eigen, which uses expression templates (not very well imo)
writing code like this
results in undefined behavior, because the
a * aproduces a temporary that contains references toa, which is then referenced by the expression holding(a * a) * a.if you store this to a local then the lifetime of that temporary is ended by the time the comparison is actually evaluated, resulting in undefined behavior
my suggested fix is to replace
do { auto expr = decomposition; } while (0)with[&](auto expr) { ... } (decomposition), but let me know if you have a different solution