Make assignment operators consistent with standard signature
This is needed to support conditionally trivially copyable Matrix and Array when they are fixed-sized, which require explicitly defaulted trivial copy assignment operators for all their base classes. But the defaulted copy assignment operators have different return types than those of the current non-trivial copy assignment operators, resulting in implicit inconsistency and potentially hard to debug behaviors.
Therefore make the non-trivial copy assignment operators of all the base classes return consistent types with the trivial ones. To ensure consistency, all other simple assignment operators are also changed in the same way.
This is an API breaking change:
Assignment operators of some Eigen classes used to return Derived&
. Now
assignment operators of every classes return references to the class itself.
Chained calls that use the return type of assignment operators, e.g.
(x = y).foo()
or return x = y;
should be updated to explicitly use the
most specific derived type, e.g. (x = y).derived().foo()
or x = y; return x;
.
Merge request reports
Activity
mentioned in issue #1855
- Resolved by Lingzhu Xiang
added 38 commits
-
b26178b7...baf9a985 - 37 commits from branch
libeigen:master
- ea64ec03 - Make copy assignment operators consistent with standard signature
-
b26178b7...baf9a985 - 37 commits from branch
added 11 commits
-
ea64ec03...9deaa191 - 10 commits from branch
libeigen:master
- e388ae07 - Make copy assignment operators consistent with standard signature
-
ea64ec03...9deaa191 - 10 commits from branch
Changes from last version:
- All (need reviews to check for missed cases)
X::operator()=
cases are changed to returnX&
, except thatSymbolExpr::operator=()
returnsSymbolValue<Tag>
. This is an exception that cannot be changed to returnSymbolExpr&
. - Quite a few cases of
Derived& Foo() { return operator=(...); }
that encounters problems converting theoperator=()
returnedBase&
toDerived&
. All are changed tooperator=(...); return *this;
oroperator=(...); return derived();
avoiding chaining assignment and return. (Need reviews to check for missed cases) - Added test helpers to fix usage of
VERIFY(x.noalias() = y, ...)
sinceNoAlias::operator=()
now returnsNoAlias
.
- All (need reviews to check for missed cases)
- Resolved by Antonio Sánchez
What's the status of this? Was the new commit too large?
added 21 commits
-
24517e7d...0c859cf3 - 19 commits from branch
libeigen:master
- 6cd2456c - Make copy assignment operators consistent with standard signature
- 1e7285be - Change all X::operator=() to return X&
-
24517e7d...0c859cf3 - 19 commits from branch
added 27 commits
-
1e7285be...9e026e5e - 25 commits from branch
libeigen:master
- 93a17b56 - Make copy assignment operators consistent with standard signature
- 48f2f97a - Change all X::operator=() to return X&
-
1e7285be...9e026e5e - 25 commits from branch
Friendly ping on this, would be great to unblock the rest of the work for making Vector trivially_copyable #1855
@cantonios do you need help with this?
Public pipeline here: https://gitlab.com/libeigen/eigen_ci_cross_testing/-/pipelines/535074654
Running some internal tests now.
added 6 commits
-
48f2f97a...73d65dbc - 4 commits from branch
libeigen:master
- 06e837be - Make copy assignment operators consistent with standard signature
- a2202877 - Change all X::operator=() to return X&
-
48f2f97a...73d65dbc - 4 commits from branch