On 11/15/2016 02:52 PM, David Malcolm wrote:
This patch addresses various bugs in the spellcheck code in which
the goal string somehow makes it into the candidate list.
The goal string will always have an edit distance of 0 to itself, and
thus is the "closest" string to the goal, but offering it as a
suggestion will always be nonsensical e.g.
  'constexpr' does not name a type; did you mean 'constexpr'?

Ultimately such suggestions are due to bugs in constructing the
candidate list.

As a band-aid, the patch updates
best_match::get_best_meaningful_candidate so that we no longer
offer suggestions for the case where the edit distance == 0
(where candidate == goal).

Doing so fixes PR c++/72786, PR c++/77922, and PR c++/78313.

I looked at fixing the candidate list in each of these bugs.

PR c++/72786 (macro defined after use): this occurs because we're
using the set of macro names at the end of parsing, rather than
at the point of parsing the site of the would-be macro usage.
A better fix would be to indicate this, but would be somewhat
invasive, needing a new internal API (perhaps too much for
stage 3?) so hopefully the band-aid is good enough for GCC 7.

PR c++/77922: the patch updates C++'s lookup_name_fuzzy to only
suggest reserved words that are matched by "-std=" etc, which
thus eliminating bogus words from the candidate list.

PR c++/78313: I attempted to prune the candidate list here, but it
led to a worse message (see the comment in that bug), hence I'd
prefer to rely on the best_match::get_best_meaningful_candidate
fix for this one.

Successfully bootstrapped&regrtested on x86_64-pc-linux-gnu; adds
26 PASS results to g++.sum.

OK for trunk?

gcc/cp/ChangeLog:
        PR c++/77922
        * name-lookup.c (lookup_name_fuzzy): Filter out reserved words
        that were filtered out by init_reswords.

gcc/ChangeLog:
        PR c++/72774
        PR c++/72786
        PR c++/77922
        PR c++/78313
        * spellcheck.c (selftest::test_find_closest_string): Verify that
        we don't offer the goal string as a suggestion.
        * spellcheck.h (best_match::get_best_meaningful_candidate): Don't
        offer the goal string as a suggestion.

gcc/testsuite/ChangeLog:
        PR c++/72774
        PR c++/72786
        PR c++/77922
        PR c++/78313
        * g++.dg/spellcheck-c++-11-keyword.C: New test case.
        * g++.dg/spellcheck-macro-ordering.C: New test case.
        * g++.dg/spellcheck-pr78313.C: New test case.
OK.  Sorry for the delays.

jeff

Reply via email to