[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
Tue Aug 6 12:00:32 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 feedback. I've added `enum`.

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


More information about the cfe-commits mailing list