public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/marxin/heads/PR105564-improve-option-completion)] opts: improve option suggestion
@ 2022-05-11 14:09 Martin Liska
0 siblings, 0 replies; only message in thread
From: Martin Liska @ 2022-05-11 14:09 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:eca8547d25dd693d65d16e15799126ee27107ffa
commit eca8547d25dd693d65d16e15799126ee27107ffa
Author: Martin Liska <mliska@suse.cz>
Date: Wed May 11 16:07:25 2022 +0200
opts: improve option suggestion
In case where we have 2 equally good candidates like
-ftrivial-auto-var-init=
-Wtrivial-auto-var-init
for -ftrivial-auto-var-init, we should take the candidate that
has a difference in trailing sign symbol.
PR driver/105564
gcc/ChangeLog:
* spellcheck.cc (test_find_closest_string): Add new test.
* spellcheck.h (class best_match): Prefer a difference in
trailing sign symbol.
Diff:
---
gcc/spellcheck.cc | 9 +++++++++
gcc/spellcheck.h | 17 ++++++++++++++---
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/gcc/spellcheck.cc b/gcc/spellcheck.cc
index 3e58344f510..f728573331f 100644
--- a/gcc/spellcheck.cc
+++ b/gcc/spellcheck.cc
@@ -464,6 +464,15 @@ test_find_closest_string ()
ASSERT_STREQ ("DWARF_GNAT_ENCODINGS_ALL",
find_closest_string ("DWARF_GNAT_ENCODINGS_all",
&candidates));
+
+ /* Example from PR 105564 where option name with missing equal
+ sign should win. */
+ candidates.truncate (0);
+ candidates.safe_push ("-Wtrivial-auto-var-init");
+ candidates.safe_push ("-ftrivial-auto-var-init=");
+ ASSERT_STREQ ("-ftrivial-auto-var-init=",
+ find_closest_string ("-ftrivial-auto-var-init",
+ &candidates));
}
/* Test data for test_metric_conditions. */
diff --git a/gcc/spellcheck.h b/gcc/spellcheck.h
index 9b6223695be..9111ea08fc3 100644
--- a/gcc/spellcheck.h
+++ b/gcc/spellcheck.h
@@ -128,11 +128,22 @@ class best_match
/* Otherwise, compute the distance and see if the candidate
has beaten the previous best value. */
+ const char *candidate_str = candidate_traits::get_string (candidate);
edit_distance_t dist
- = get_edit_distance (m_goal, m_goal_len,
- candidate_traits::get_string (candidate),
- candidate_len);
+ = get_edit_distance (m_goal, m_goal_len, candidate_str, candidate_len);
+
+ bool is_better = false;
if (dist < m_best_distance)
+ is_better = true;
+ else if (dist == m_best_distance)
+ {
+ /* Prefer a candidate has a difference in trailing sign character. */
+ if (candidate_str[candidate_len - 1] == '='
+ && m_goal[m_goal_len - 1] != '=')
+ is_better = true;
+ }
+
+ if (is_better)
{
m_best_distance = dist;
m_best_candidate = candidate;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-05-11 14:09 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-11 14:09 [gcc(refs/users/marxin/heads/PR105564-improve-option-completion)] opts: improve option suggestion Martin Liska
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).