aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r--lib/Sema/SemaDecl.cpp26
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index c90b7492a2..cc8ec878cc 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -7262,14 +7262,38 @@ NamedDecl *Sema::ImplicitlyDefineFunction(SourceLocation Loc,
return Pos->second;
}
+ // See if we can find a typo correction.
+ TypoCorrection Corrected;
+ FunctionDecl *Func = 0;
+ std::string CorrectedStr;
+ std::string CorrectedQuotedStr;
+ if (S && (Corrected = CorrectTypo(DeclarationNameInfo(&II, Loc),
+ LookupOrdinaryName, S, 0))) {
+ // Since this is an implicit function declaration, we are only
+ // interested in a potential typo for a function name.
+ if ((Func = dyn_cast_or_null<FunctionDecl>(
+ Corrected.getCorrectionDecl()))) {
+ CorrectedStr = Corrected.getAsString(getLangOptions());
+ CorrectedQuotedStr = Corrected.getQuoted(getLangOptions());
+ }
+ }
+
// Extension in C99. Legal in C90, but warn about it.
if (II.getName().startswith("__builtin_"))
- Diag(Loc, diag::warn_builtin_unknown) << &II;
+ Diag(Loc, diag::err_builtin_unknown) << &II;
else if (getLangOptions().C99)
Diag(Loc, diag::ext_implicit_function_decl) << &II;
else
Diag(Loc, diag::warn_implicit_function_decl) << &II;
+ if (Func) {
+ // If we found a typo correction, then suggest that.
+ Diag(Loc, diag::note_function_suggestion) << CorrectedQuotedStr
+ << FixItHint::CreateReplacement(Loc, CorrectedStr);
+ if (Func->getLocation().isValid() && !II.getName().startswith("__builtin_"))
+ Diag(Func->getLocation(), diag::note_previous_decl) << CorrectedQuotedStr;
+ }
+
// Set a Declarator for the implicit definition: int foo();
const char *Dummy;
AttributeFactory attrFactory;