On Mon, Oct 05, 2020 at 09:39:01AM -0400, Nathan Sidwell wrote: > My change to namespace-scope spell corrections ignored the issue that > different targets might have different builtins, and therefore perturb > iteration order. This fixes it by using an intermediate array of > identifier, which we sort before considering. > > gcc/cp/ > * name-lookup.c (maybe_add_fuzzy_decl): New. > (maybe_add_fuzzy_binding): New. > (consider_binding_level): Use intermediate sortable vector for > namespace bindings. > gcc/testsuite/ > * c-c++-common/spellcheck-reserved.c: Restore diagnostic.
Won't that be unnecessarily expensive? I mean, as implemented, it will push into the vector all non-artificial decls, so perhaps tens of thousands of them into the vector, then qsort the vector and only then consider it. So, either the code could hand-inline parts of what consider method considers and only push into vectors decls that have the currently best distance (and when encountering a better one truncate the vector before pushing in). Or add spellcheck.h consider alternative that would from candidates with the same distance choose some particular one (e.g. the one where strcmp says it compares earlier). The if (min_candidate_distance >= m_best_distance) would probably need changing to > and then have dist == m_best_distance handling. Jakub