[clang] [Clang] strengthen checks for 'main' function to meet [basic.start.main] p2 requirements (PR #101853)

Mital Ashok via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 5 01:28:01 PDT 2024


================
@@ -7353,6 +7353,15 @@ void emitReadOnlyPlacementAttrWarning(Sema &S, const VarDecl *VD) {
   }
 }
 
+static bool isMainVar(DeclarationName Name, VarDecl *VD) {
+  if (Name.getAsIdentifierInfo() && Name.getAsIdentifierInfo()->isStr("main") &&
+      !VD->getDescribedVarTemplate()) {
+    const DeclContext *DC = VD->getDeclContext();
+    return DC->getRedeclContext()->isTranslationUnit() || DC->isLinkageSpec();
----------------
MitalAshok wrote:

This doesn't seem to catch `extern "C" { namespace NS { int main; } }`

```suggestion
    return DC->getRedeclContext()->isTranslationUnit() ||
           VD->getLanguageLinkage() == CLanguageLinkage;
```

https://github.com/llvm/llvm-project/pull/101853


More information about the cfe-commits mailing list