Avoid unexpected behavior if move/copy is incorrectly implemented #577
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.
ChaiScript 6 always used a shared_ptr to wrap C++ objects created in
ChaiScript. Newer versions avoid this by only wrapping objects that cannot
be copied. This has the side effect that ChaiScript depends on correctly
implemented C++ copy and move constructors in unexpected locations.
I don't think the reduced overhead (by avoiding the shared_ptr) justifies
the new behavior in every case.
Therefore, I suggest we temporarily only perform this optimization if the class
is trivially destructible, until unexpected copies and moves in ChaiScript
are fixed (if this is even possible), or there is a sanitizer/compiler warning
that can detect these cases.
Before the change the following code will call the ctor once, move once,
and the dtor twice:
auto obj = MoveableObject();
After this change it will only call the ctor once and the dtor once.