Skip to content

Use empty() instead of size()==0, size()<1 #1032

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

Merged
merged 1 commit into from
Jun 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ansi-c/c_typecheck_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2566,7 +2566,7 @@ exprt c_typecheck_baset::do_special_functions(
// http://gcc.gnu.org/onlinedocs/gcc-4.1.1/gcc/Atomic-Builtins.html

// adjust return type of function to match pointer subtype
if(expr.arguments().size()<1)
if(expr.arguments().empty())
{
err_location(f_op);
error() << "__sync_* primitives take as least one argument" << eom;
Expand Down
2 changes: 1 addition & 1 deletion src/ansi-c/expr2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2588,7 +2588,7 @@ std::string expr2ct::convert_code_switch(
const codet &src,
unsigned indent)
{
if(src.operands().size()<1)
if(src.operands().empty())
{
unsigned precedence;
return convert_norep(src, precedence);
Expand Down
2 changes: 1 addition & 1 deletion src/clobber/clobber_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ bool clobber_parse_optionst::get_goto_program(
const optionst &options,
goto_functionst &goto_functions)
{
if(cmdline.args.size()==0)
if(cmdline.args.empty())
{
error() << "Please provide a program to verify" << eom;
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/cpp_typecheck_compound_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ void cpp_typecheckt::typecheck_compound_declarator(
{
is_virtual=true;
const code_typet &code_type=to_code_type(comp.type());
assert(code_type.parameters().size()>0);
assert(!code_type.parameters().empty());
const typet &pointer_type=code_type.parameters()[0].type();
assert(pointer_type.id()==ID_pointer);
virtual_bases.insert(pointer_type.subtype().get(ID_identifier));
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/cpp_typecheck_conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,13 +574,13 @@ bool cpp_typecheckt::standard_conversion_pointer_to_member(
expr.type().subtype().id()==ID_code)
{
code_typet code1=to_code_type(expr.type().subtype());
assert(code1.parameters().size()>0);
assert(!code1.parameters().empty());
code_typet::parametert this1=code1.parameters()[0];
assert(this1.get(ID_C_base_name)==ID_this);
code1.parameters().erase(code1.parameters().begin());

code_typet code2=to_code_type(type.subtype());
assert(code2.parameters().size()>0);
assert(!code2.parameters().empty());
code_typet::parametert this2=code2.parameters()[0];
assert(this2.get(ID_C_base_name)==ID_this);
code2.parameters().erase(code2.parameters().begin());
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/cpp_typecheck_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1431,7 +1431,7 @@ void cpp_typecheckt::typecheck_expr_cpp_name(
// http://gcc.gnu.org/onlinedocs/gcc-4.1.1/gcc/Atomic-Builtins.html

// adjust return type of function to match pointer subtype
if(fargs.operands.size()<1)
if(fargs.operands.empty())
{
error().source_location=source_location;
error() << "__sync_* primitives take as least one argument"
Expand Down
8 changes: 4 additions & 4 deletions src/goto-cc/compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ bool compilet::doit()
return true;
}

if(mode==LINK_LIBRARY && source_files.size()>0)
if(mode==LINK_LIBRARY && !source_files.empty())
{
error() << "cannot link source files" << eom;
return true;
}

if(mode==PREPROCESS_ONLY && object_files.size()>0)
if(mode==PREPROCESS_ONLY && !object_files.empty())
{
error() << "cannot preprocess object files" << eom;
return true;
Expand All @@ -117,7 +117,7 @@ bool compilet::doit()
const unsigned warnings_before=
get_message_handler().get_message_count(messaget::M_WARNING);

if(source_files.size()>0)
if(!source_files.empty())
if(compile())
return true;

Expand Down Expand Up @@ -346,7 +346,7 @@ bool compilet::link()
convert_symbols(compiled_functions);

// parse object files
while(object_files.size()>0)
while(!object_files.empty())
{
std::string file_name=object_files.front();
object_files.pop_front();
Expand Down
1 change: 0 additions & 1 deletion src/goto-cc/xml_binaries/xml_goto_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@ void convert(const xmlt &xml, goto_functionst::goto_functiont &function)
{
function.body.clear();
convert(xml, function.body);
function.body_available = function.body.instructions.size()>0;
// don't forget to fix the functions type via the symbol table!
}
1 change: 0 additions & 1 deletion src/goto-cc/xml_binaries/xml_goto_function_hashing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,5 @@ void xml_goto_function_convertt::convert(
xml_goto_program_convertt gpconverter(ireps_container);
function.body.clear();
gpconverter.convert(xml, function.body);
function.body_available = function.body.instructions.size()>0;
// don't forget to fix the functions type via the symbol table!
}
2 changes: 1 addition & 1 deletion src/goto-cc/xml_binaries/xml_symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void convert(const symbolt &sym, xmlt &root)
flags.new_element("base_name").data=id2string(sym.base_name);
flags.new_element("module").data=id2string(sym.module);

if(sym.pretty_name.size()>0)
if(!sym.pretty_name.empty())
flags.new_element("pretty_name").data=id2string(sym.pretty_name);

xmlt &xmlloc = xmlsym.new_element("location");
Expand Down
2 changes: 1 addition & 1 deletion src/goto-instrument/accelerate/acceleration_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ bool acceleration_utilst::do_arrays(
<< " array assignments\n";
#endif

if(array_assignments.size()==0)
if(array_assignments.empty())
{
// The loop doesn't write to any arrays. We're done!
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/goto-instrument/accelerate/trace_automaton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ void automatont::reverse(goto_programt::targett epsilon)
transitions.push_back(transitionst());
}

if(accept_states.size()==0)
if(accept_states.empty())
{
num_states=0;
return;
Expand Down
4 changes: 2 additions & 2 deletions src/goto-instrument/rw_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,13 @@ class rw_set_with_trackt:public _rw_set_loct

void track_deref(const entryt &entry, bool read)
{
if(dereferencing && dereferenced.size()==0)
if(dereferencing && dereferenced.empty())
{
dereferenced.insert(dereferenced.begin(), entry);
if(read)
set_reads.insert(entry.object);
}
else if(dereferencing && dereferenced.size()>0)
else if(dereferencing && !dereferenced.empty())
dereferenced_from.insert(
std::make_pair(entry.object, dereferenced.front().object));
}
Expand Down
6 changes: 3 additions & 3 deletions src/goto-instrument/wmm/cycle_collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,21 +521,21 @@ bool event_grapht::graph_explorert::backtrack(

std::stack<event_idt> tmp;

while(marked_stack.size()>0 && marked_stack.top()!=vertex)
while(!marked_stack.empty() && marked_stack.top()!=vertex)
{
tmp.push(marked_stack.top());
mark[marked_stack.top()]=false;
marked_stack.pop();
}

if(marked_stack.size()>0)
if(!marked_stack.empty())
{
assert(marked_stack.top()==vertex);
mark[vertex]=true;
}
else
{
while(tmp.size()>0)
while(!tmp.empty())
{
marked_stack.push(tmp.top());
mark[tmp.top()]=true;
Expand Down
4 changes: 2 additions & 2 deletions src/goto-instrument/wmm/event_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void event_grapht::print_rec_graph(std::ofstream &file, event_idt node_id,

void event_grapht::print_graph()
{
assert(po_order.size()>0);
assert(!po_order.empty());
std::set<event_idt> visited;
event_idt root=po_order.front();
std::ofstream file;
Expand Down Expand Up @@ -113,7 +113,7 @@ event_idt event_grapht::copy_segment(event_idt begin, event_idt end)
/* collects the nodes of the subgraph */
explore_copy_segment(covered, begin, end);

if(covered.size()==0)
if(covered.empty())
return end;

// for(std::set<event_idt>::const_iterator it=covered.begin();
Expand Down
2 changes: 1 addition & 1 deletion src/goto-instrument/wmm/event_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class event_grapht
{
critical_cyclet reduced(egraph, id);
this->hide_internals(reduced);
assert(reduced.size()>0);
assert(!reduced.empty());
return print_name(reduced, model);
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/goto-instrument/wmm/weak_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void weak_memory(
<<" cycles found"<<messaget::eom;

/* if no cycle, no need to instrument */
if(instrumenter.set_of_cycles.size() == 0)
if(instrumenter.set_of_cycles.empty())
{
message.status()<<"program safe -- no need to instrument"<<messaget::eom;
return;
Expand Down
4 changes: 2 additions & 2 deletions src/goto-programs/builtin_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ void goto_convertt::do_scanf(

if(f_id==CPROVER_PREFIX "scanf")
{
if(arguments.size()<1)
if(arguments.empty())
{
error().source_location=function.find_source_location();
error() << "scanf takes at least one argument" << eom;
Expand Down Expand Up @@ -1328,7 +1328,7 @@ void goto_convertt::do_function_call_symbol(
}
else if(identifier==CPROVER_PREFIX "fence")
{
if(arguments.size()<1)
if(arguments.empty())
{
error().source_location=function.find_source_location();
error() << "`" << identifier
Expand Down
4 changes: 2 additions & 2 deletions src/goto-programs/interpreter_evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void interpretert::evaluate(
}
else if(expr.id()==ID_or)
{
if(expr.operands().size()<1)
if(expr.operands().empty())
throw id2string(expr.id())+" expects at least one operand";

bool result=false;
Expand Down Expand Up @@ -188,7 +188,7 @@ void interpretert::evaluate(
}
else if(expr.id()==ID_and)
{
if(expr.operands().size()<1)
if(expr.operands().empty())
throw id2string(expr.id())+" expects at least one operand";

bool result=true;
Expand Down
2 changes: 1 addition & 1 deletion src/goto-programs/remove_unused_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void remove_unused_functions(

messaget message(message_handler);

if(unused_functions.size()>0)
if(!unused_functions.empty())
{
message.statistics()
<< "Dropping " << unused_functions.size() << " of " <<
Expand Down
2 changes: 1 addition & 1 deletion src/goto-programs/show_goto_functions_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ json_objectt show_goto_functions_jsont::convert(
instruction_entry["instruction"]=
json_stringt(instruction_builder.str());

if(instruction.code.operands().size()>0)
if(!instruction.code.operands().empty())
{
json_arrayt operand_array;
for(const exprt &operand : instruction.code.operands())
Expand Down
6 changes: 3 additions & 3 deletions src/java_bytecode/java_bytecode_convert_method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1772,7 +1772,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
}
else if(statement=="putfield")
{
assert(op.size()==2 && results.size()==0);
assert(op.size()==2 && results.empty());
code_blockt block;
save_stack_entries(
"stack_field",
Expand Down Expand Up @@ -1948,7 +1948,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
else if(statement=="tableswitch" ||
statement=="lookupswitch")
{
assert(op.size()==1 && results.size()==0);
assert(op.size()==1 && results.empty());

// we turn into switch-case
code_switcht code_switch;
Expand Down Expand Up @@ -2298,7 +2298,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
code_labelt newlabel(label(std::to_string(address)), code_blockt());
root_block.move_to_operands(newlabel);
root.branch.push_back(block_tree_nodet::get_leaf());
assert((root.branch_addresses.size()==0 ||
assert((root.branch_addresses.empty() ||
root.branch_addresses.back()<address) &&
"Block addresses should be unique and increasing");
root.branch_addresses.push_back(address);
Expand Down
2 changes: 1 addition & 1 deletion src/java_bytecode/java_bytecode_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ bool java_bytecode_languaget::do_ci_lazy_method_conversion(
do
{
any_new_methods=false;
while(method_worklist2.size()!=0)
while(!method_worklist2.empty())
{
std::swap(method_worklist1, method_worklist2);
for(const auto &mname : method_worklist1)
Expand Down
2 changes: 1 addition & 1 deletion src/memory-models/mmcc_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int mmcc_parse_optionst::doit()

return convert(in, cmdline.args[0]);
}
else if(cmdline.args.size()==0)
else if(cmdline.args.empty())
{
return convert(std::cin, "stdin");
}
Expand Down
2 changes: 1 addition & 1 deletion src/musketeer/cycles_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ void cycles_visitort::com_constraint(

std::list<event_idt>::const_iterator e_it=C_j.begin();
std::list<event_idt>::const_iterator next_it=e_it;
assert(C_j.size()>0);
assert(!C_j.empty());
++next_it;
for(; next_it!=C_j.end() && e_it!=C_j.end(); ++e_it, ++next_it)
{
Expand Down
2 changes: 1 addition & 1 deletion src/musketeer/fencer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void fence_weak_memory(
<< " cycles found" << messaget::eom;

/* if no cycle, no need to instrument */
if(instrumenter.set_of_cycles.size() == 0)
if(instrumenter.set_of_cycles.empty())
{
message.result()
<< "program safe -- no need to place additional fences"
Expand Down
14 changes: 7 additions & 7 deletions src/musketeer/graph_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void const_graph_visitort::graph_explore(
edges.insert(fence_inserter.add_edge(edget(*it, *next_it)));
}
}
else if(egraph.po_out(next).size()==0)
else if(egraph.po_out(next).empty())
{
/* this path is not connecting a to b => return */
}
Expand Down Expand Up @@ -76,7 +76,7 @@ void const_graph_visitort::const_graph_explore(
fence_inserter.add_edge(edget(*it, *next_it));
}
}
else if(egraph.po_out(next).size()==0)
else if(egraph.po_out(next).empty())
{
/* this path is not connecting a to b => return */
}
Expand Down Expand Up @@ -106,7 +106,7 @@ void const_graph_visitort::graph_explore_BC(
bool porw)
{
/* TODO: restricts to C_1 U ... U C_n for perf improvement */
assert(old_path.size()>0);
assert(!old_path.empty());

fence_inserter.instrumenter.message.debug() << "(BC) explore "
<< old_path.front()
Expand All @@ -129,7 +129,7 @@ void const_graph_visitort::graph_explore_BC(
break;
}

if(egraph.po_out(next).size()==0 || no_other_pos)
if(egraph.po_out(next).empty() || no_other_pos)
{
/* inserts all the pos collected from old_path in edges */
std::list<event_idt>::const_iterator it=old_path.begin();
Expand Down Expand Up @@ -184,7 +184,7 @@ void const_graph_visitort::const_graph_explore_BC(
break;
}

if(egraph.po_out(next).size()==0 || no_other_pos)
if(egraph.po_out(next).empty() || no_other_pos)
{
/* inserts all the pos collected from old_path in edges */
std::list<event_idt>::const_iterator it=old_path.begin();
Expand Down Expand Up @@ -244,7 +244,7 @@ void const_graph_visitort::graph_explore_AC(
break;
}

if(egraph.po_in(next).size()==0 || no_other_pos)
if(egraph.po_in(next).empty() || no_other_pos)
{
/* inserts all the pos collected from old_path in edges */
std::list<event_idt>::const_iterator it=old_path.begin();
Expand Down Expand Up @@ -300,7 +300,7 @@ void const_graph_visitort::const_graph_explore_AC(
}

/* if beginning of the thread */
if(egraph.po_in(next).size()==0 || no_other_pos)
if(egraph.po_in(next).empty() || no_other_pos)
{
/* inserts all the pos collected from old_path in edges */
std::list<event_idt>::const_iterator it=old_path.begin();
Expand Down
Loading