aboutsummaryrefslogtreecommitdiff
path: root/lib/Basic/DiagnosticIDs.cpp
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2011-11-15 12:26:39 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2011-11-15 12:26:39 +0000
commitdce6327160a6e333137b34cce77e2dfc2cd5aab6 (patch)
treeb3c9761cd9f8857e4cc879fc515e0e5b22fdf9a5 /lib/Basic/DiagnosticIDs.cpp
parentf7ce19400ba4d7e7f17f804490b76035de6fdf5e (diff)
Warning option typo correction: When two options have the same edit_distance don't display either.
Also add a maximum edit distance threshold, so we don't correct "-Wx" to "-W#pragma-messages". git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144644 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Basic/DiagnosticIDs.cpp')
-rw-r--r--lib/Basic/DiagnosticIDs.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/Basic/DiagnosticIDs.cpp b/lib/Basic/DiagnosticIDs.cpp
index 39fee69adb..cbca8d1c76 100644
--- a/lib/Basic/DiagnosticIDs.cpp
+++ b/lib/Basic/DiagnosticIDs.cpp
@@ -683,7 +683,7 @@ bool DiagnosticIDs::getDiagnosticsInGroup(
StringRef DiagnosticIDs::getNearestWarningOption(StringRef Group) {
StringRef Best;
- unsigned BestDistance = 0;
+ unsigned BestDistance = Group.size() + 1; // Sanity threshold.
for (const WarningOption *i = OptionTable, *e = OptionTable + OptionTableSize;
i != e; ++i) {
// Don't suggest ignored warning flags.
@@ -691,9 +691,11 @@ StringRef DiagnosticIDs::getNearestWarningOption(StringRef Group) {
continue;
unsigned Distance = i->getName().edit_distance(Group, true, BestDistance);
-
- // Check if this is a better match.
- if (Best.empty() || Distance < BestDistance) {
+ if (Distance == BestDistance) {
+ // Two matches with the same distance, don't prefer one over the other.
+ Best = "";
+ } else if (Distance < BestDistance) {
+ // This is a better match.
Best = i->getName();
BestDistance = Distance;
}