Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Pending code changes (auto-populated)
Maintained by go/gitwatcher - Please do not modify manually [ID: 530458]
Maintained by go/gitwatcher - Please do not modify manually [ID: 530406]
View issue level access limits(Press Alt + Right arrow for more information)
Request for new functionality
View staffing
Description
Pop quiz! What value does the following Reactor code produce:
The answer is 4.
While this code may appear to implement swapping two array elements,
auto x
evaluates toReference<Int> x
. It merely holds the address ofa[0]
(i.e. it's like writingint &x
in C++). So when we assign it toa[1]
at line 8, it copies the value 2 which was previously assigned toa[0]
at line 7.This can be made to behave more like C code by having
Reference<T>
also store the dereferenced value on creation. This value can then be returned on implicit casts toT
, instead of doing the load at that time. One caveat might be that when memory is writeable but not readable, an expression likea[0] = x
could produce a read violation. This could be addressed by eliminating the load when a store to the reference has happened instead.By deriving
Referece<T>
fromT
we could also support things likea[0].x
where we're indexing into an array of vectors and and accessing a component of a vector.It might also be worth looking into whether we can discern between left-hand-side and right-hand-side usage by using rvalue references in constructors and/or operators.