[clang] [Clang] strengthen checks for 'main' function to meet [basic.start.main] p3 requirements (PR #101853)
Mital Ashok via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 16 01:58:27 PDT 2024
================
@@ -12210,7 +12220,18 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD,
return Redeclaration;
}
-void Sema::CheckMain(FunctionDecl* FD, const DeclSpec& DS) {
+void Sema::CheckMain(FunctionDecl *FD, const DeclSpec &DS) {
+ // [basic.start.main]p3
+ // The main function shall not be declared with a linkage-specification.
+ if (FD->isExternCContext() ||
+ (FD->isExternCXXContext() &&
+ FD->getDeclContext()->getRedeclContext()->isTranslationUnit())) {
+ Diag(FD->getLocation(), diag::ext_main_invalid_linkage_specification)
+ << FD->getLanguageLinkage();
+ FD->setInvalidDecl();
+ return;
----------------
MitalAshok wrote:
```suggestion
```
@alexfh I think these lines are probably what's causing the crash (if it's allowed as an extension, it should not be marked invalid, and we need to diagnose/check the other stuff if we have `-Wno-main`).
Either way, could you open a new GitHub issue for visibility?
https://github.com/llvm/llvm-project/pull/101853
More information about the cfe-commits
mailing list