Skip to content

Commit 03e6856

Browse files
committed
Avoid evaluation-order warnings with Visual Studio
Constructing the arguments in place triggers a warning with Visual Studio. Just construct them in a fixed order upfront and move each of them.
1 parent bbc9a80 commit 03e6856

File tree

9 files changed

+110
-64
lines changed

9 files changed

+110
-64
lines changed

src/analyses/ai.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,15 @@ jsont ai_baset::output_json(
9595
std::ostringstream out;
9696
goto_program.output_instruction(ns, function_id, out, *i_it);
9797

98+
json_numbert location_number_json(std::to_string(i_it->location_number));
99+
json_stringt source_location_json(i_it->source_location.as_string());
100+
jsont abstract_state_json(abstract_state_before(i_it)->output_json(*this, ns));
101+
json_stringt instruction_json(out.str());
98102
json_objectt location(
99-
{{"locationNumber", json_numbert(std::to_string(i_it->location_number))},
100-
{"sourceLocation", json_stringt(i_it->source_location.as_string())},
101-
{"abstractState", abstract_state_before(i_it)->output_json(*this, ns)},
102-
{"instruction", json_stringt(out.str())}});
103+
{{"locationNumber", std::move(location_number_json)},
104+
{"sourceLocation", std::move(source_location_json)},
105+
{"abstractState", std::move(abstract_state_json)},
106+
{"instruction", std::move(instruction_json)}});
103107

104108
contents.push_back(std::move(location));
105109
}

src/goto-analyzer/unreachable_instructions.cpp

+15-7
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,13 @@ static void add_to_json(
118118
{{"function", json_stringt(function_identifier)},
119119
{"fileName",
120120
json_stringt(concat_dir_file(
121+
// json_stringt function_json(end_function->function);
122+
// json_stringt file_name_json(concat_dir_file(
121123
id2string(end_function->source_location.get_working_directory()),
122-
id2string(end_function->source_location.get_file())))}});
124+
id2string(end_function->source_location.get_file())));
125+
//json_objectt entry(
126+
// {{"function", std::move(function_json)},
127+
//{"fileName", std::move(file_name_json)}});
123128

124129
json_arrayt &dead_ins=entry["unreachableInstructions"].make_array();
125130

@@ -142,8 +147,10 @@ static void add_to_json(
142147

143148
// print info for file actually with full path
144149
const source_locationt &l=it->second->source_location;
150+
jsont source_location_json(json(l));
151+
json_stringt statement_json(s);
145152
json_objectt i_entry(
146-
{{"sourceLocation", json(l)}, {"statement", json_stringt(s)}});
153+
{{"sourceLocation", std::move(source_location_json)}, {"statement", std::move(statement_json)}});
147154
dead_ins.push_back(std::move(i_entry));
148155
}
149156

@@ -246,12 +253,13 @@ static void json_output_function(
246253
const source_locationt &last_location,
247254
json_arrayt &dest)
248255
{
249-
json_objectt entry(
250-
{{"function", json_stringt(function)},
251-
{"file name",
252-
json_stringt(concat_dir_file(
256+
json_stringt function_json(function);
257+
json_stringt file_name_json(concat_dir_file(
253258
id2string(first_location.get_working_directory()),
254-
id2string(first_location.get_file())))},
259+
id2string(first_location.get_file())));
260+
json_objectt entry(
261+
{{"function", std::move(function_json)},
262+
{"file name", std::move(file_name_json)},
255263
{"first line", json_numbert(id2string(first_location.get_line()))},
256264
{"last line", json_numbert(id2string(last_location.get_line()))}});
257265

src/goto-checker/properties.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ std::string as_string(property_statust status)
5656

5757
property_infot::property_infot(
5858
goto_programt::const_targett pc,
59-
std::string description,
59+
const std::string &description,
6060
property_statust status)
61-
: pc(pc), description(std::move(description)), status(status)
61+
: pc(pc), description(description), status(status)
6262
{
6363
}
6464

@@ -80,9 +80,8 @@ propertiest initialize_properties(const abstract_goto_modelt &goto_model)
8080
std::string description = id2string(i_it->source_location.get_comment());
8181
if(description.empty())
8282
description = "assertion";
83-
properties.emplace(
84-
i_it->source_location.get_property_id(),
85-
property_infot{i_it, description, property_statust::NOT_CHECKED});
83+
property_infot info{i_it, description, property_statust::NOT_CHECKED};
84+
properties.emplace(i_it->source_location.get_property_id(), std::move(info));
8685
}
8786
}
8887
return properties;

src/goto-checker/properties.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct property_infot
5757
{
5858
property_infot(
5959
goto_programt::const_targett pc,
60-
std::string description,
60+
const std::string &description,
6161
property_statust status);
6262

6363
/// A pointer to the corresponding goto instruction

src/goto-diff/goto_diff_base.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ void goto_difft::output_functions() const
3838
}
3939
case ui_message_handlert::uit::JSON_UI:
4040
{
41+
json_stringt total_number_of_functions_json(std::to_string(total_functions_count));
4142
json_objectt json_result(
42-
{{"totalNumberOfFunctions",
43-
json_stringt(std::to_string(total_functions_count))}});
43+
{{"totalNumberOfFunctions", std::move(total_number_of_functions_json)}});
4444
convert_function_group_json(
4545
json_result["newFunctions"].make_array(), new_functions, goto_model2);
4646
convert_function_group_json(

src/goto-programs/loop_ids.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,11 @@ void show_loop_ids_json(
8181
{
8282
std::string id = id2string(goto_programt::loop_id(function_id, *it));
8383

84+
json_stringt name_json(id);
85+
jsont source_location_json(json(it->source_location));
8486
loops.push_back(
85-
json_objectt({{"name", json_stringt(id)},
86-
{"sourceLocation", json(it->source_location)}}));
87+
json_objectt({{"name", std::move(name_json)},
88+
{"sourceLocation", std::move(source_location_json)}}));
8789
}
8890
}
8991
}

src/goto-programs/show_goto_functions_json.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ json_objectt show_goto_functions_jsont::convert(
7070
for(const goto_programt::instructiont &instruction :
7171
function.body.instructions)
7272
{
73+
json_stringt instruction_id(instruction.to_string());
7374
json_objectt instruction_entry(
74-
{{"instructionId", json_stringt(instruction.to_string())}});
75+
{{"instructionId", std::move(instruction_id)}});
7576

7677
if(instruction.code.source_location().is_not_nil())
7778
{

src/goto-programs/show_properties.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,17 @@ void convert_properties_json(
129129

130130
irep_idt property_id=source_location.get_property_id();
131131

132+
json_stringt name_json(property_id);
133+
json_stringt class_json(property_class);
134+
jsont source_location_json(json(source_location));
135+
json_stringt description_json(description);
136+
json_stringt expression_json(from_expr(ns, identifier, ins.guard));
132137
json_objectt json_property(
133-
{{"name", json_stringt(property_id)},
134-
{"class", json_stringt(property_class)},
135-
{"sourceLocation", json(source_location)},
136-
{"description", json_stringt(description)},
137-
{"expression", json_stringt(from_expr(ns, identifier, ins.guard))}});
138+
{{"name", std::move(name_json)},
139+
{"class", std::move(class_json)},
140+
{"sourceLocation", std::move(source_location_json)},
141+
{"description", std::move(description_json)},
142+
{"expression", std::move(expression_json)}});
138143

139144
if(!source_location.get_basic_block_covered_lines().empty())
140145
json_property["coveredLines"] =

src/goto-programs/show_symbol_table.cpp

+64-37
Original file line numberDiff line numberDiff line change
@@ -194,36 +194,59 @@ static void show_symbol_table_json_ui(
194194
if(symbol.value.is_not_nil())
195195
ptr->from_expr(symbol.value, value_str, ns);
196196

197+
json_stringt pretty_name_json(symbol.pretty_name);
198+
json_stringt name_json(symbol.name);
199+
json_stringt base_name_json(symbol.base_name);
200+
json_stringt mode_json(symbol.mode);
201+
json_stringt module_json(symbol.module);
202+
json_stringt pretty_type_json(type_str);
203+
json_stringt pretty_value_json(value_str);
204+
jsont type_json(irep_converter.convert_from_irep(symbol.type));
205+
jsont value_json(irep_converter.convert_from_irep(symbol.value));
206+
jsont location_json(irep_converter.convert_from_irep(symbol.location));
207+
jsont is_type_json(jsont::json_boolean(symbol.is_type));
208+
jsont is_macro_json(jsont::json_boolean(symbol.is_macro));
209+
jsont is_exported_json(jsont::json_boolean(symbol.is_exported));
210+
jsont is_input_json(jsont::json_boolean(symbol.is_input));
211+
jsont is_output_json(jsont::json_boolean(symbol.is_output));
212+
jsont is_state_var_json(jsont::json_boolean(symbol.is_state_var));
213+
jsont is_property_json(jsont::json_boolean(symbol.is_property));
214+
jsont is_static_lifetime_json(jsont::json_boolean(symbol.is_static_lifetime));
215+
jsont is_thread_local_json(jsont::json_boolean(symbol.is_thread_local));
216+
jsont is_lvalue_json(jsont::json_boolean(symbol.is_lvalue));
217+
jsont is_file_local_json(jsont::json_boolean(symbol.is_file_local));
218+
jsont is_extern_json(jsont::json_boolean(symbol.is_extern));
219+
jsont is_volatile_json(jsont::json_boolean(symbol.is_volatile));
220+
jsont is_parameter_json(jsont::json_boolean(symbol.is_parameter));
221+
jsont is_auxiliary_json(jsont::json_boolean(symbol.is_auxiliary));
222+
jsont is_weak_json(jsont::json_boolean(symbol.is_weak));
197223
json_objectt symbol_json(
198-
{{"prettyName", json_stringt(symbol.pretty_name)},
199-
{"name", json_stringt(symbol.name)},
200-
{"baseName", json_stringt(symbol.base_name)},
201-
{"mode", json_stringt(symbol.mode)},
202-
{"module", json_stringt(symbol.module)},
203-
204-
{"prettyType", json_stringt(type_str)},
205-
{"prettyValue", json_stringt(value_str)},
206-
207-
{"type", irep_converter.convert_from_irep(symbol.type)},
208-
{"value", irep_converter.convert_from_irep(symbol.value)},
209-
{"location", irep_converter.convert_from_irep(symbol.location)},
210-
211-
{"isType", jsont::json_boolean(symbol.is_type)},
212-
{"isMacro", jsont::json_boolean(symbol.is_macro)},
213-
{"isExported", jsont::json_boolean(symbol.is_exported)},
214-
{"isInput", jsont::json_boolean(symbol.is_input)},
215-
{"isOutput", jsont::json_boolean(symbol.is_output)},
216-
{"isStateVar", jsont::json_boolean(symbol.is_state_var)},
217-
{"isProperty", jsont::json_boolean(symbol.is_property)},
218-
{"isStaticLifetime", jsont::json_boolean(symbol.is_static_lifetime)},
219-
{"isThreadLocal", jsont::json_boolean(symbol.is_thread_local)},
220-
{"isLvalue", jsont::json_boolean(symbol.is_lvalue)},
221-
{"isFileLocal", jsont::json_boolean(symbol.is_file_local)},
222-
{"isExtern", jsont::json_boolean(symbol.is_extern)},
223-
{"isVolatile", jsont::json_boolean(symbol.is_volatile)},
224-
{"isParameter", jsont::json_boolean(symbol.is_parameter)},
225-
{"isAuxiliary", jsont::json_boolean(symbol.is_auxiliary)},
226-
{"isWeak", jsont::json_boolean(symbol.is_weak)}});
224+
{{"prettyName", std::move(pretty_name_json)},
225+
{"name", std::move(name_json)},
226+
{"baseName", std::move(base_name_json)},
227+
{"mode", std::move(mode_json)},
228+
{"module", std::move(module_json)},
229+
{"prettyType", std::move(pretty_type_json)},
230+
{"prettyValue", std::move(pretty_value_json)},
231+
{"type", std::move(type_json)},
232+
{"value", std::move(value_json)},
233+
{"location", std::move(location_json)},
234+
{"isType", std::move(is_type_json)},
235+
{"isMacro", std::move(is_macro_json)},
236+
{"isExported", std::move(is_exported_json)},
237+
{"isInput", std::move(is_input_json)},
238+
{"isOutput", std::move(is_output_json)},
239+
{"isStateVar", std::move(is_state_var_json)},
240+
{"isProperty", std::move(is_property_json)},
241+
{"isStaticLifetime", std::move(is_static_lifetime_json)},
242+
{"isThreadLocal", std::move(is_thread_local_json)},
243+
{"isLvalue", std::move(is_lvalue_json)},
244+
{"isFileLocal", std::move(is_file_local_json)},
245+
{"isExtern", std::move(is_extern_json)},
246+
{"isVolatile", std::move(is_volatile_json)},
247+
{"isParameter", std::move(is_parameter_json)},
248+
{"isAuxiliary", std::move(is_auxiliary_json)},
249+
{"isWeak", std::move(is_weak_json)}});
227250

228251
result.push_back(id2string(symbol.name), std::move(symbol_json));
229252
}
@@ -265,15 +288,19 @@ static void show_symbol_table_brief_json_ui(
265288
if(symbol.type.is_not_nil())
266289
ptr->from_type(symbol.type, type_str, ns);
267290

291+
json_stringt pretty_name_json(symbol.pretty_name);
292+
json_stringt base_name_json(symbol.base_name);
293+
json_stringt mode_json(symbol.mode);
294+
json_stringt module_json(symbol.module);
295+
json_stringt pretty_type_json(type_str);
296+
jsont type_json(irep_converter.convert_from_irep(symbol.type));
268297
json_objectt symbol_json(
269-
{{"prettyName", json_stringt(symbol.pretty_name)},
270-
{"baseName", json_stringt(symbol.base_name)},
271-
{"mode", json_stringt(symbol.mode)},
272-
{"module", json_stringt(symbol.module)},
273-
274-
{"prettyType", json_stringt(type_str)},
275-
276-
{"type", irep_converter.convert_from_irep(symbol.type)}});
298+
{{"prettyName", std::move(pretty_name_json)},
299+
{"baseName", std::move(base_name_json)},
300+
{"mode", std::move(mode_json)},
301+
{"module", std::move(module_json)},
302+
{"prettyType", std::move(pretty_type_json)},
303+
{"type", std::move(type_json)}});
277304

278305
result.push_back(id2string(symbol.name), std::move(symbol_json));
279306
}

0 commit comments

Comments
 (0)