[cfe-commits] r113324 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/FixIt/fixit.cpp
Gabor Greif
ggreif at gmail.com
Tue Sep 7 17:31:13 PDT 2010
Author: ggreif
Date: Tue Sep 7 19:31:13 2010
New Revision: 113324
URL: http://llvm.org/viewvc/llvm-project?rev=113324&view=rev
Log:
add a fixit when 'main' does ot return 'int'; review welcome
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/FixIt/fixit.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=113324&r1=113323&r2=113324&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Sep 7 19:31:13 2010
@@ -3171,7 +3171,7 @@
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 @@
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);
}
Modified: cfe/trunk/test/FixIt/fixit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit.cpp?rev=113324&r1=113323&r2=113324&view=diff
==============================================================================
--- cfe/trunk/test/FixIt/fixit.cpp (original)
+++ cfe/trunk/test/FixIt/fixit.cpp Tue Sep 7 19:31:13 2010
@@ -60,3 +60,9 @@
}
}
+
+CT<1> main(void); // expected-error{{'main' must return 'int'}}
+
+// typedef CT<1> mainT(void);
+// mainT main; // TODO
+
More information about the cfe-commits
mailing list