From a4a301dc74dd4e7da1c35cbb3c1e03614482728b Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Wed, 8 Sep 2010 00:31:13 +0000 Subject: [PATCH] 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 --- lib/Sema/SemaDecl.cpp | 12 +++++++++--- test/FixIt/fixit.cpp | 6 ++++++ 2 files changed, 15 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(); 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(&TL)) { + D << FixItHint::CreateReplacement(PTL->getResultLoc().getSourceRange(), + "int"); + } FD->setInvalidDecl(true); } diff --git a/test/FixIt/fixit.cpp b/test/FixIt/fixit.cpp index 5a28132397..9b39c9e8a5 100644 --- a/test/FixIt/fixit.cpp +++ b/test/FixIt/fixit.cpp @@ -60,3 +60,9 @@ namespace rdar7796492 { } } + +CT<1> main(void); // expected-error{{'main' must return 'int'}} + +// typedef CT<1> mainT(void); +// mainT main; // TODO + -- 2.40.0