diff options
author | Gabor Greif <ggreif@gmail.com> | 2010-09-08 00:31:13 +0000 |
---|---|---|
committer | Gabor Greif <ggreif@gmail.com> | 2010-09-08 00:31:13 +0000 |
commit | a4a301dc74dd4e7da1c35cbb3c1e03614482728b (patch) | |
tree | e903f637546ad1d0574c4ddbeb411398b6a558f4 /lib/Sema/SemaDecl.cpp | |
parent | ab6677ec401cfd2c82b34e4cdfebd55a9dc25778 (diff) |
add a fixit when 'main' does ot return 'int'; review welcome
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113324 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index df077fd709..2b42fb60fb 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -3171,7 +3171,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, SC = SC_Static; break; } - case DeclSpec::SCS_private_extern: SC = SC_PrivateExtern;break; + case DeclSpec::SCS_private_extern: SC = SC_PrivateExtern; break; } if (D.getDeclSpec().isThreadSpecified()) @@ -3976,8 +3976,14 @@ void Sema::CheckMain(FunctionDecl* FD) { const FunctionType* FT = T->getAs<FunctionType>(); if (!Context.hasSameUnqualifiedType(FT->getResultType(), Context.IntTy)) { - // TODO: add a replacement fixit to turn the return type into 'int'. - Diag(FD->getTypeSpecStartLoc(), diag::err_main_returns_nonint); + TypeSourceInfo *TSI = FD->getTypeSourceInfo(); + TypeLoc TL = TSI->getTypeLoc(); + const SemaDiagnosticBuilder& D = Diag(FD->getTypeSpecStartLoc(), + diag::err_main_returns_nonint); + if (FunctionTypeLoc* PTL = dyn_cast<FunctionTypeLoc>(&TL)) { + D << FixItHint::CreateReplacement(PTL->getResultLoc().getSourceRange(), + "int"); + } FD->setInvalidDecl(true); } |