Use make_unique to reset editor's Current_mission

This commit is contained in:
Kp 2016-08-06 19:55:25 +00:00
parent 53deef077a
commit b449986ea8
2 changed files with 23 additions and 1 deletions

View file

@ -145,6 +145,27 @@ struct Mission : Mission_path
descent_version_type descent_version; // descent 1 or descent 2?
std::unique_ptr<d_fname> alternate_ham_file;
#endif
/* Explicitly default move constructor and move operator=
*
* Without this, gcc (tested gcc-4.9, gcc-5) tries to use
* a synthetic operator=(const Mission &) to implement `instance =
* {};`, which fails because Mission contains std::unique_ptr, a
* movable but noncopyable type.
*
* With the explicit default, gcc uses operator=(Mission &&), which
* works.
*
* Explicitly default the default constructor since the explicitly
* defaulted move constructor suppresses the implicit default
* constructor.
* Explicitly delete copy constructor and copy operator= for
* thoroughness.
*/
Mission(Mission &&) = default;
Mission &operator=(Mission &&) = default;
Mission() = default;
Mission(const Mission &) = delete;
Mission &operator=(const Mission &) = delete;
~Mission();
};

View file

@ -1078,7 +1078,8 @@ int select_mission(int anarchy_mode, const char *message, int (*when_selected)(v
#ifdef EDITOR
void create_new_mission(void)
{
Current_mission.reset(new Mission{});
Current_mission = make_unique<Mission>();
*Current_mission = {};
Current_mission->path = "new_mission";
Current_mission->filename = begin(Current_mission->path);