Skip to content

Commit dc7b8c8

Browse files
peterschrammeltautschnig
authored andcommitted
Fix disambiguation
Code cleanup and fix segmentation fault in erase-while-iterate.
1 parent c9f3334 commit dc7b8c8

File tree

1 file changed

+40
-40
lines changed

1 file changed

+40
-40
lines changed

src/cpp/cpp_typecheck_resolve.cpp

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -484,54 +484,47 @@ void cpp_typecheck_resolvet::disambiguate_functions(
484484
}
485485
}
486486

487-
identifiers.clear();
487+
old_identifiers.clear();
488488

489489
// put in the top ones
490490
if(!distance_map.empty())
491491
{
492-
std::size_t distance=distance_map.begin()->first;
493-
494-
for(std::multimap<std::size_t, exprt>::const_iterator
495-
it=distance_map.begin();
496-
it!=distance_map.end() && it->first==distance;
497-
it++)
498-
identifiers.push_back(it->second);
492+
auto range=distance_map.equal_range(distance_map.begin()->first);
493+
for(auto it=range.first; it!=range.second; ++it)
494+
old_identifiers.push_back(it->second);
499495
}
500496

501-
if(identifiers.size()>1 && fargs.in_use)
497+
if(old_identifiers.size()>1 && fargs.in_use)
502498
{
503499
// try to further disambiguate functions
504500

505-
for(resolve_identifierst::iterator
506-
it1=identifiers.begin();
507-
it1!=identifiers.end();
508-
it1++)
501+
for(resolve_identifierst::const_iterator
502+
old_it=old_identifiers.begin();
503+
old_it!=old_identifiers.end();
504+
++old_it)
509505
{
510-
if(it1->type().id()!=ID_code)
506+
#if 0
507+
std::cout << "I1: " << old_it->get(ID_identifier) << '\n';
508+
#endif
509+
510+
if(old_it->type().id()!=ID_code)
511+
{
512+
identifiers.push_back(*old_it);
511513
continue;
514+
}
512515

513516
const code_typet &f1=
514-
to_code_type(it1->type());
517+
to_code_type(old_it->type());
515518

516-
for(resolve_identifierst::iterator it2=
517-
identifiers.begin();
518-
it2!=identifiers.end();
519-
) // no it2++
519+
for(resolve_identifierst::const_iterator resolve_it=old_it+1;
520+
resolve_it!=old_identifiers.end();
521+
++resolve_it)
520522
{
521-
if(it1 == it2)
522-
{
523-
it2++;
524-
continue;
525-
}
526-
527-
if(it2->type().id()!=ID_code)
528-
{
529-
it2++;
523+
if(resolve_it->type().id()!=ID_code)
530524
continue;
531-
}
532525

533526
const code_typet &f2 =
534-
to_code_type(it2->type());
527+
to_code_type(resolve_it->type());
535528

536529
// TODO: may fail when using ellipsis
537530
assert(f1.parameters().size() == f2.parameters().size());
@@ -577,20 +570,24 @@ void cpp_typecheck_resolvet::disambiguate_functions(
577570
{
578571
f2_better=false;
579572
}
580-
else if(f2_better && cpp_typecheck.subtype_typecast(struct2, struct1))
573+
else if(f2_better &&
574+
cpp_typecheck.subtype_typecast(struct2, struct1))
581575
{
582576
f1_better=false;
583577
}
584578
}
585579

586-
resolve_identifierst::iterator prev_it=it2;
587-
it2++;
588-
589-
if(f1_better && !f2_better)
590-
identifiers.erase(prev_it);
580+
if(!f1_better || f2_better)
581+
identifiers.push_back(*resolve_it);
591582
}
592583
}
593584
}
585+
else
586+
{
587+
identifiers.swap(old_identifiers);
588+
}
589+
590+
remove_duplicates(identifiers);
594591
}
595592

596593
void cpp_typecheck_resolvet::make_constructors(
@@ -935,7 +932,9 @@ cpp_scopet &cpp_typecheck_resolvet::resolve_scope(
935932
id_set);
936933

937934
#ifdef DEBUG
938-
std::cout << "S: " << cpp_typecheck.cpp_scopes.current_scope().identifier << std::endl;
935+
std::cout << "S: "
936+
<< cpp_typecheck.cpp_scopes.current_scope().identifier
937+
<< std::endl;
939938
cpp_typecheck.cpp_scopes.current_scope().print(std::cout);
940939
std::cout << "X: " << id_set.size() <<std::endl;
941940
#endif
@@ -1418,7 +1417,8 @@ exprt cpp_typecheck_resolvet::resolve(
14181417
std::cout << "base name: " << base_name << std::endl;
14191418
std::cout << "template args: " << template_args << std::endl;
14201419
std::cout << "original-scope: " << original_scope->prefix << std::endl;
1421-
std::cout << "scope: " << cpp_typecheck.cpp_scopes.current_scope().prefix << std::endl;
1420+
std::cout << "scope: "
1421+
<< cpp_typecheck.cpp_scopes.current_scope().prefix << std::endl;
14221422
#endif
14231423

14241424
const source_locationt &source_location=cpp_name.source_location();
@@ -1610,8 +1610,8 @@ exprt cpp_typecheck_resolvet::resolve(
16101610
std::cout << "\n";
16111611
#endif
16121612
}
1613-
1614-
remove_duplicates(new_identifiers);
1613+
else
1614+
remove_duplicates(new_identifiers);
16151615

16161616
#if 0
16171617
std::cout << "P4 " << base_name << " " << new_identifiers.size() << "\n";

0 commit comments

Comments
 (0)