summaryrefslogtreecommitdiffstats
path: root/clang/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
commit176a5cb38abee0ed735c8c19c7a9c984ff4fe4f8 (patch)
treed1f00990730253e6e02735f28f5cc92e83075134 /clang/lib/Basic/DiagnosticIDs.cpp
parenteb21b70d931eabb7b12e5d074d56f71cf43cdbd1 (diff)
downloadbcm5719-llvm-176a5cb38abee0ed735c8c19c7a9c984ff4fe4f8.tar.gz
bcm5719-llvm-176a5cb38abee0ed735c8c19c7a9c984ff4fe4f8.zip
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". llvm-svn: 144644
Diffstat (limited to 'clang/lib/Basic/DiagnosticIDs.cpp')
-rw-r--r--clang/lib/Basic/DiagnosticIDs.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/clang/lib/Basic/DiagnosticIDs.cpp b/clang/lib/Basic/DiagnosticIDs.cpp
index 39fee69adbe..cbca8d1c769 100644
--- a/clang/lib/Basic/DiagnosticIDs.cpp
+++ b/clang/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;
}
OpenPOWER on IntegriCloud