def err_not_a_pch_file : Error<
"'%0' does not appear to be a precompiled header file">, DefaultFatal;
def warn_unknown_warning_option : Warning<
- "unknown warning option '%0'">,
+ "unknown warning option '%0'; did you mean '%1'?">,
InGroup<DiagGroup<"unknown-warning-option"> >;
def warn_unknown_negative_warning_option : Warning<
- "unknown warning option '%0'">,
+ "unknown warning option '%0'; did you mean '%1'?">,
InGroup<DiagGroup<"unknown-warning-option"> >, DefaultIgnore;
def warn_unknown_warning_specifier : Warning<
"unknown %0 warning specifier: '%1'">,
bool getDiagnosticsInGroup(StringRef Group,
llvm::SmallVectorImpl<diag::kind> &Diags) const;
+ /// \brief Get the warning option with the closest edit distance to the given
+ /// group name.
+ static StringRef getNearestWarningOption(StringRef Group);
+
private:
/// \brief Get the set of all diagnostic IDs in the given group.
///
return false;
}
+StringRef DiagnosticIDs::getNearestWarningOption(StringRef Group) {
+ StringRef Best;
+ unsigned BestDistance = 0;
+ for (const WarningOption *i = OptionTable, *e = OptionTable + OptionTableSize;
+ i != e; ++i) {
+ // Don't suggest ignored warning flags.
+ if (!i->Members && !i->SubGroups)
+ continue;
+
+ unsigned Distance = i->getName().edit_distance(Group, true, BestDistance);
+
+ // Check if this is a better match.
+ if (Best.empty() || Distance < BestDistance) {
+ Best = i->getName();
+ BestDistance = Distance;
+ }
+ }
+
+ return Best;
+}
+
/// ProcessDiag - This is the method used to report a diagnostic that is
/// finally fully formed.
bool DiagnosticIDs::ProcessDiag(DiagnosticsEngine &Diag) const {
} else if (DiagIDs->getDiagnosticsInGroup(Specifier, _Diags)) {
Diags.Report(isPositive ? diag::warn_unknown_warning_option :
diag::warn_unknown_negative_warning_option)
- << ("-W" + Opt.str());
+ << ("-W" + Opt.str())
+ << ("-Werror=" +
+ DiagnosticIDs::getNearestWarningOption(Specifier).str());
}
continue;
}
} else if (DiagIDs->getDiagnosticsInGroup(Specifier, _Diags)) {
Diags.Report(isPositive ? diag::warn_unknown_warning_option :
diag::warn_unknown_negative_warning_option)
- << ("-W" + Opt.str());
+ << ("-W" + Opt.str())
+ << ("-Wfatal-errors=" +
+ DiagnosticIDs::getNearestWarningOption(Specifier).str());
}
continue;
}
if (Report && DiagIDs->getDiagnosticsInGroup(Opt, _Diags)) {
Diags.Report(isPositive ? diag::warn_unknown_warning_option :
diag::warn_unknown_negative_warning_option)
- << ("-W" + Opt.str());
+ << ("-W" + Opt.str())
+ << ("-W" + DiagnosticIDs::getNearestWarningOption(Opt).str());
} else {
Diags.setDiagnosticGroupMapping(Opt, Mapping);
}
// CHECK: <key>level</key>
// CHECK: <string>warning</string>
// CHECK: <key>message</key>
-// CHECK: <string>unknown warning option '-Wfoobar'</string>
+// CHECK: <string>unknown warning option '-Wfoobar'; did you mean '-W{{.*}}'?</string>
// CHECK: </dict>
// CHECK: <dict>
// CHECK: <key>level</key>