Fixed bug in dyn_var implementation where returns from [] and * cause bug #73
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.
A recent change (#65) simplified the implementation of pointer types esp. struct types so that the overloaded * and [] operators returned dyn_var instead of builder. This allowed accessing members from these easier. However this causes a major bug where if the user writes code snippets like -
the copy a is completely removed. This is because the operators construct the returned object using (builder::cast). Due to copy elision, a itself is constructed with (cast) causing errors. If a is used multiple times, each use will have ptr[i]. Bugs arise when ptr[i] has side effects.
This bug was discovered while implementing a toy language interpreter with @tekknolagi
To fix this issue, we introduce a clone of dyn_var called dyn_var_mimic which is exactly like dyn_var (inherits from dyn_var), but IS NOT dyn_var. We return this type from the operator. Thus is the user directly accesses the members, the behavior is the same like before, but if a dyn_var is constructed from such an expression, copy elision doesn't happen and a copy is created.
Minor change where dyn_var_parent_selector now strips of references from types before inheriting so dyn_var<T&> also have members. This is unrelated to above.
Sample38 is updated to test this.