Skip to content

Commit 389fbcd

Browse files
Removed copy constructor from goto_function_templatet
Rather than telling people not to use the copy constructor, actually don't use it
1 parent 8c4d8c5 commit 389fbcd

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

src/goto-instrument/wmm/goto2graph.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -1532,13 +1532,12 @@ bool instrumentert::is_cfg_spurious(const event_grapht::critical_cyclet &cyc)
15321532
}
15331533

15341534
/* now test whether this part of the code can exist */
1535+
goto_functionst::function_mapt map;
15351536
goto_function_templatet<goto_programt> one_interleaving;
15361537
one_interleaving.body.copy_from(interleaving);
1537-
1538-
std::pair<irep_idt, goto_function_templatet<goto_programt> > p(
1539-
goto_functionst::entry_point(), one_interleaving);
1540-
goto_functionst::function_mapt map;
1541-
map.insert(p);
1538+
map.insert(std::make_pair(
1539+
goto_functionst::entry_point(),
1540+
std::move(one_interleaving)));
15421541

15431542
goto_functionst this_interleaving;
15441543
this_interleaving.function_map=std::move(map);

src/goto-programs/goto_functions.h

+23
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,29 @@ Date: June 2003
1717
class goto_functionst:public goto_functions_templatet<goto_programt>
1818
{
1919
public:
20+
goto_functionst()=default;
21+
22+
// Copying is unavailable as base class copy is deleted
23+
// MSVC is unable to automatically determine this
24+
goto_functionst(const goto_functionst &)=delete;
25+
goto_functionst &operator=(const goto_functionst &)=delete;
26+
27+
// Move operations need to be explicitly enabled as they are deleted with the
28+
// copy operations
29+
// default for move operations isn't available on Windows yet, so define
30+
// explicitly (see https://msdn.microsoft.com/en-us/library/hh567368.aspx
31+
// under "Defaulted and Deleted Functions")
32+
33+
goto_functionst(goto_functionst &&other):
34+
goto_functions_templatet(std::move(other))
35+
{
36+
}
37+
38+
goto_functionst &operator=(goto_functionst &&other)
39+
{
40+
goto_functions_templatet::operator=(std::move(other));
41+
return *this;
42+
}
2043
};
2144

2245
#define Forall_goto_functions(it, functions) \

src/goto-programs/goto_functions_template.h

+13-9
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,8 @@ class goto_function_templatet
7373
parameter_identifiers=other.parameter_identifiers;
7474
}
7575

76-
goto_function_templatet(const goto_function_templatet &other)
77-
: type(other.type),
78-
parameter_identifiers(other.parameter_identifiers)
79-
{
80-
body.copy_from(other.body);
81-
}
76+
goto_function_templatet(const goto_function_templatet &)=delete;
77+
goto_function_templatet &operator=(const goto_function_templatet &)=delete;
8278

8379
goto_function_templatet(goto_function_templatet &&other):
8480
body(std::move(other.body)),
@@ -108,10 +104,18 @@ class goto_functions_templatet
108104
{
109105
}
110106

111-
// copy constructor, don't use me!
112-
goto_functions_templatet(const goto_functions_templatet<bodyT> &src)
107+
goto_functions_templatet(const goto_functions_templatet &)=delete;
108+
goto_functions_templatet &operator=(const goto_functions_templatet &)=delete;
109+
110+
goto_functions_templatet(goto_functions_templatet &&other):
111+
function_map(std::move(other.function_map))
112+
{
113+
}
114+
115+
goto_functions_templatet &operator=(goto_functions_templatet &&other)
113116
{
114-
assert(src.function_map.empty());
117+
function_map=std::move(other.function_map);
118+
return *this;
115119
}
116120

117121
void clear()

0 commit comments

Comments
 (0)