Skip to content

Commit 611888c

Browse files
peterschrammeltautschnig
authored andcommitted
Fix disambiguation
Code cleanup and fix segmentation fault in erase-while-iterate.
1 parent 2ebe1e9 commit 611888c

File tree

1 file changed

+33
-40
lines changed

1 file changed

+33
-40
lines changed

src/cpp/cpp_typecheck_resolve.cpp

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -463,54 +463,44 @@ void cpp_typecheck_resolvet::disambiguate_functions(
463463
}
464464
}
465465

466-
identifiers.clear();
466+
old_identifiers.clear();
467467

468468
// put in the top ones
469469
if(!distance_map.empty())
470470
{
471-
std::size_t distance=distance_map.begin()->first;
472-
473-
for(std::multimap<std::size_t, exprt>::const_iterator
474-
it=distance_map.begin();
475-
it!=distance_map.end() && it->first==distance;
476-
it++)
477-
identifiers.push_back(it->second);
471+
auto range = distance_map.equal_range(distance_map.begin()->first);
472+
for(auto it = range.first; it != range.second; ++it)
473+
old_identifiers.push_back(it->second);
478474
}
479475

480-
if(identifiers.size()>1 && fargs.in_use)
476+
if(old_identifiers.size() > 1 && fargs.in_use)
481477
{
482478
// try to further disambiguate functions
483479

484-
for(resolve_identifierst::iterator
485-
it1=identifiers.begin();
486-
it1!=identifiers.end();
487-
it1++)
480+
for(resolve_identifierst::const_iterator old_it = old_identifiers.begin();
481+
old_it != old_identifiers.end();
482+
++old_it)
488483
{
489-
if(it1->type().id()!=ID_code)
484+
#if 0
485+
std::cout << "I1: " << old_it->get(ID_identifier) << '\n';
486+
#endif
487+
488+
if(old_it->type().id() != ID_code)
489+
{
490+
identifiers.push_back(*old_it);
490491
continue;
492+
}
491493

492-
const code_typet &f1=
493-
to_code_type(it1->type());
494+
const code_typet &f1 = to_code_type(old_it->type());
494495

495-
for(resolve_identifierst::iterator it2=
496-
identifiers.begin();
497-
it2!=identifiers.end();
498-
) // no it2++
496+
for(resolve_identifierst::const_iterator resolve_it = old_it + 1;
497+
resolve_it != old_identifiers.end();
498+
++resolve_it)
499499
{
500-
if(it1 == it2)
501-
{
502-
it2++;
503-
continue;
504-
}
505-
506-
if(it2->type().id()!=ID_code)
507-
{
508-
it2++;
500+
if(resolve_it->type().id() != ID_code)
509501
continue;
510-
}
511502

512-
const code_typet &f2 =
513-
to_code_type(it2->type());
503+
const code_typet &f2 = to_code_type(resolve_it->type());
514504

515505
// TODO: may fail when using ellipsis
516506
assert(f1.parameters().size() == f2.parameters().size());
@@ -562,14 +552,17 @@ void cpp_typecheck_resolvet::disambiguate_functions(
562552
}
563553
}
564554

565-
resolve_identifierst::iterator prev_it=it2;
566-
it2++;
567-
568-
if(f1_better && !f2_better)
569-
identifiers.erase(prev_it);
555+
if(!f1_better || f2_better)
556+
identifiers.push_back(*resolve_it);
570557
}
571558
}
572559
}
560+
else
561+
{
562+
identifiers.swap(old_identifiers);
563+
}
564+
565+
remove_duplicates(identifiers);
573566
}
574567

575568
void cpp_typecheck_resolvet::make_constructors(
@@ -1566,10 +1559,10 @@ exprt cpp_typecheck_resolvet::resolve(
15661559
std::cout << "\n";
15671560
#endif
15681561
}
1562+
else
1563+
remove_duplicates(new_identifiers);
15691564

1570-
remove_duplicates(new_identifiers);
1571-
1572-
#if 0
1565+
#if 0
15731566
std::cout << "P4 " << base_name << " " << new_identifiers.size() << "\n";
15741567
show_identifiers(base_name, new_identifiers, std::cout);
15751568
std::cout << "\n";

0 commit comments

Comments
 (0)