https://github.com/ashwinbanwari updated 
https://github.com/llvm/llvm-project/pull/146247

>From f2ed0c7989d7e181004237a4fa2ba7ae1efe44ed Mon Sep 17 00:00:00 2001
From: Ashwin Banwari <ashwinkbanw...@gmail.com>
Date: Sat, 28 Jun 2025 16:19:55 -0700
Subject: [PATCH 1/3] add err_main_in_named_module

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 1 +
 clang/lib/Sema/SemaDecl.cpp                      | 8 ++++++++
 2 files changed, 9 insertions(+)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 5062505cf3c01..94f08300c3dcb 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1062,6 +1062,7 @@ def err_constexpr_main : Error<
   "'main' is not allowed to be declared %select{constexpr|consteval}0">;
 def err_deleted_main : Error<"'main' is not allowed to be deleted">;
 def err_mainlike_template_decl : Error<"%0 cannot be a template">;
+def err_main_in_named_module : Error<"'main' cannot be attached to a named 
module">;
 def err_main_returns_nonint : Error<"'main' must return 'int'">;
 def ext_main_returns_nonint : ExtWarn<"return type of 'main' is not 'int'">,
     InGroup<MainReturnType>;
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index e1cccf068b5aa..c4ddfda9f447f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -12490,6 +12490,14 @@ void Sema::CheckMain(FunctionDecl *FD, const DeclSpec 
&DS) {
                                 : FixItHint());
       FD->setInvalidDecl(true);
     }
+
+    // In C++ [basic.start.main]p3, it is said a program attaching main to a
+    // named module is ill-formed.
+    if (FD->isInNamedModule()) {
+      Diag(FD->getTypeSpecStartLoc(), diag::err_main_in_named_module)
+          << FixItHint();
+      FD->setInvalidDecl(true);
+    }
   }
 
   // Treat protoless main() as nullary.

>From b721f8ff73a67cb3485876e4b4c0de48cc59d194 Mon Sep 17 00:00:00 2001
From: Ashwin Banwari <ashwinkbanw...@gmail.com>
Date: Sat, 28 Jun 2025 16:32:20 -0700
Subject: [PATCH 2/3] git clang-format HEAD~1

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 94f08300c3dcb..ce9017ded0087 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1062,7 +1062,8 @@ def err_constexpr_main : Error<
   "'main' is not allowed to be declared %select{constexpr|consteval}0">;
 def err_deleted_main : Error<"'main' is not allowed to be deleted">;
 def err_mainlike_template_decl : Error<"%0 cannot be a template">;
-def err_main_in_named_module : Error<"'main' cannot be attached to a named 
module">;
+def err_main_in_named_module
+    : Error<"'main' cannot be attached to a named module">;
 def err_main_returns_nonint : Error<"'main' must return 'int'">;
 def ext_main_returns_nonint : ExtWarn<"return type of 'main' is not 'int'">,
     InGroup<MainReturnType>;

>From 6130b53fc4051a618c612f1d852c7d85557644d2 Mon Sep 17 00:00:00 2001
From: Ashwin Banwari <ashwinkbanw...@gmail.com>
Date: Sat, 28 Jun 2025 16:47:02 -0700
Subject: [PATCH 3/3] don't need FixItHint() ?

---
 clang/lib/Sema/SemaDecl.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index c4ddfda9f447f..064e145ff502f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -12494,8 +12494,7 @@ void Sema::CheckMain(FunctionDecl *FD, const DeclSpec 
&DS) {
     // In C++ [basic.start.main]p3, it is said a program attaching main to a
     // named module is ill-formed.
     if (FD->isInNamedModule()) {
-      Diag(FD->getTypeSpecStartLoc(), diag::err_main_in_named_module)
-          << FixItHint();
+      Diag(FD->getTypeSpecStartLoc(), diag::err_main_in_named_module);
       FD->setInvalidDecl(true);
     }
   }

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to