[clang] 8a5b97a - Revert "[clang] [modules] Add err_main_in_named_module (#146247)"
Chuanqi Xu via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 30 08:22:49 PDT 2025
Author: Chuanqi Xu
Date: 2025-06-30T23:22:31+08:00
New Revision: 8a5b97a7205db189ca82f44dec7a399c2b5da546
URL: https://github.com/llvm/llvm-project/commit/8a5b97a7205db189ca82f44dec7a399c2b5da546
DIFF: https://github.com/llvm/llvm-project/commit/8a5b97a7205db189ca82f44dec7a399c2b5da546.diff
LOG: Revert "[clang] [modules] Add err_main_in_named_module (#146247)"
This reverts commit 473769ec9b2f860813229eb449fb4298dfc7ff94.
It breaks test in libc++
See https://github.com/llvm/llvm-project/pull/146247
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDecl.cpp
clang/test/Driver/autocomplete.c
clang/test/SemaCXX/modules.cppm
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f13d99845ee9a..d3e7ea0e73219 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -655,9 +655,6 @@ Improvements to Clang's diagnostics
#GH69470, #GH59391, #GH58172, #GH46215, #GH45915, #GH45891, #GH44490,
#GH36703, #GH32903, #GH23312, #GH69874.
-- A warning is now emitted when ``main`` is attached to a named module,
- which can be turned off with ``-Wno-main-attached-to-named-module``. (#GH146247)
-
- Clang now avoids issuing `-Wreturn-type` warnings in some cases where
the final statement of a non-void function is a `throw` expression, or
a call to a function that is trivially known to always throw (i.e., its
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 451619709c087..5062505cf3c01 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1062,10 +1062,6 @@ 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 warn_main_in_named_module
- : ExtWarn<"'main' should not be attached to a named module; consider "
- "adding C++ language linkage">,
- InGroup<DiagGroup<"main-attached-to-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 f4bc191d1dae6..a34e2c9cbb003 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -12489,14 +12489,6 @@ 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()) {
- const SourceLocation start = FD->getTypeSpecStartLoc();
- Diag(start, diag::warn_main_in_named_module)
- << FixItHint::CreateInsertion(start, "extern \"C++\" ", true);
- }
}
// Treat protoless main() as nullary.
diff --git a/clang/test/Driver/autocomplete.c b/clang/test/Driver/autocomplete.c
index 4983b71496834..8cc604dbff875 100644
--- a/clang/test/Driver/autocomplete.c
+++ b/clang/test/Driver/autocomplete.c
@@ -111,7 +111,6 @@
// RUN: %clang --autocomplete=-Wma | FileCheck %s -check-prefix=WARNING
// WARNING: -Wmacro-redefined
// WARNING-NEXT: -Wmain
-// WARNING-NEXT: -Wmain-attached-to-named-module
// WARNING-NEXT: -Wmain-return-type
// WARNING-NEXT: -Wmalformed-warning-check
// WARNING-NEXT: -Wmany-braces-around-scalar-init
diff --git a/clang/test/SemaCXX/modules.cppm b/clang/test/SemaCXX/modules.cppm
index 81bc749c58259..5d0d6da44a2ed 100644
--- a/clang/test/SemaCXX/modules.cppm
+++ b/clang/test/SemaCXX/modules.cppm
@@ -68,8 +68,6 @@ int n;
//--- test3.cpp
export module bar;
-int main() {} // expected-warning {{'main' should not be attached to a named module; consider adding C++ language linkage}}
-
static int m;
int n;
More information about the cfe-commits
mailing list