Skip to content

Enable goto_modelt move assignment #880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

NathanJPhillips
Copy link
Contributor

@NathanJPhillips NathanJPhillips commented Apr 28, 2017

Previously goto_modelt implemented a non-standard move constructor and didn't enable the assignment operator. This replaces that code with the standard way of achieving the desired result.
This also removes the copy constructor from goto_functions_templatet rather than just telling people not to use it.

@reuk
Copy link
Contributor

reuk commented Apr 28, 2017

This fails on windows because it doesn't understand noexcept. On other platforms this fails because the data members don't have noexcept move functions.

On clang and gcc these should be noexcept, but that would require having some macros somewhere which expand to noexcept or nothing, depending on whether that feature is supported. We should do something similar for constexpr too.

@NathanJPhillips NathanJPhillips force-pushed the feature/enable-goto-model-move-assignment branch 2 times, most recently from fc0dc98 to 75a9525 Compare May 3, 2017 11:06
goto_functions.swap(other.goto_functions);
symbol_table = std::move(other.symbol_table);
goto_functions = std::move(other.goto_functions);
return *this;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My preference is to implement operator= always in terms of swap:

swap(other);
return *this;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surely that's less efficient as you're doing two moves instead of one?

@NathanJPhillips NathanJPhillips force-pushed the feature/enable-goto-model-move-assignment branch from 75a9525 to ac8a88e Compare May 4, 2017 09:45
goto_modelt &operator=(goto_modelt &&other)
{
goto_modelt tmp(std::move(other));
swap(tmp);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This uses more stack than necessary. Can just

swap(other);
return *this;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, wasn't thinking, of course you can if it's a move assignment.

@NathanJPhillips NathanJPhillips force-pushed the feature/enable-goto-model-move-assignment branch 10 times, most recently from 6fd6cb9 to 1e2447d Compare May 10, 2017 12:48
@NathanJPhillips NathanJPhillips changed the title Enable move assignment Enable goto_modelt move assignment May 10, 2017
@NathanJPhillips NathanJPhillips changed the title Enable goto_modelt move assignment Enable goto_modelt move assignment May 10, 2017
// under "Defaulted and Deleted Functions")

goto_functionst(goto_functionst &&other)
: goto_functions_templatet(std::move(other))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put colon at end of previous line (several occurrences)

Propagate this change through goto_programt and goto_function_templatet
Rather than telling people not to use the copy constructor, actually don't use it
@NathanJPhillips NathanJPhillips force-pushed the feature/enable-goto-model-move-assignment branch from 1e2447d to 389fbcd Compare May 12, 2017 10:41
@kroening kroening merged commit fc4c0fe into diffblue:master May 15, 2017
@NathanJPhillips NathanJPhillips deleted the feature/enable-goto-model-move-assignment branch May 16, 2017 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants