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

Oleksandr T. via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 7 00:55:39 PDT 2024


================
@@ -8052,10 +8061,7 @@ NamedDecl *Sema::ActOnVariableDeclarator(
   }
 
   // Special handling of variable named 'main'.
-  if (Name.getAsIdentifierInfo() && Name.getAsIdentifierInfo()->isStr("main") &&
-      NewVD->getDeclContext()->getRedeclContext()->isTranslationUnit() &&
-      !getLangOpts().Freestanding && !NewVD->getDescribedVarTemplate()) {
-
+  if (!getLangOpts().Freestanding && isMainVar(Name, NewVD)) {
     // C++ [basic.start.main]p3
     // A program that declares a variable main at global scope is ill-formed.
----------------
a-tarasyuk wrote:

@MitalAshok Thanks for the reviews. I’ve added requested changes. 

@MitalAshok @Sirraide If there’s no further feedback, could you please proceed with the merge since I don’t have access? Thanks.

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


More information about the cfe-commits mailing list